
Originally Posted by
javapenguin
and when should I use :
(stack.top()).getX()
?
You only need parentheses if you need to cast the value returned by stack.top() to a Type that has the method getX().
For example, in GUI coding an event has a getSource() method that returns Object. If you know what subclass of Object is the source of the event, you can cast it accordingly to use its methods.
public void actionPerformed(ActionEvent e) { ((JButton) e.getSource()).setIcon(...); } // equivalent to actionPerformed(ActionEvent e) { Object o = e.getSource(); JButton button = (JButton) o; button.setIcon(...); } db