File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Why include all operators in the precedence hierachy? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Why include all operators in the precedence hierachy?" Watch "Why include all operators in the precedence hierachy?" New topic
Author

Why include all operators in the precedence hierachy?

Simon Smith
Greenhorn

Joined: Aug 15, 2006
Posts: 3
Hi,

I am puzzled as to why all operators are listed in the precedence hierachy.

For example it makes perfect sense to have a hierachy for Addition/Multiplication operators so that you can make sense of:

int i = 4 * 9 + 3;

However, why state that the postfix increment operator is of greater precedence that the prefix increment operator? Surely, under any conditions that I can think of they would be goeverned by the associativity rule.

For example :

int i = 1;
int j = i++ + ++i;

The precednce of postfix/prefix are irrelanvent as the operands of the addition operator are evaluated left to right.

There must be a reason, so if any of you good folks could provide me with an example of why precedence rules exist for all operators I would be very grateful.

Thanks in advance,

Simon
wise owen
Ranch Hand

Joined: Feb 02, 2006
Posts: 2023
Hope this may help.
Simon Smith
Greenhorn

Joined: Aug 15, 2006
Posts: 3
Hi

Thanks for that. It is an interesting article but it doesn't provide an example of when the precedence of a postfix increment over a prefix increment operator would be relevant.

Thanks

Simon
 
Don't get me started about those stupid light bulbs.
 
subject: Why include all operators in the precedence hierachy?