File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes post - pre increment Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "post - pre increment" Watch "post - pre increment" New topic
Author

post - pre increment

mohit joshi
Ranch Hand

Joined: Sep 23, 2000
Posts: 243
I have a doubt
JLS 15.14.1 says
the result of the postfix expression must be a variable of a numeric type, or a compile time error occurs.
JLS 15.15.1 says

the result of prefix increment expression is not a variable, but a value.

what exacly does it signify. I thought that it would be possible to do something like x++ = y ( because result of x++ is a variable) but it doesnt work like that.
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671
If you look at the entire first paragraph of 15.14.1 and the entire first paragraph of 15.15.1, you find that they are nearly identical - the only difference is that the word "prefix" is replaced with "postfix". You are comparing two quotes from different positions in the paragraphs, without looking carefully at the exact wording. No need to look at two different sections to get those sentences - you can find nearly the same sentences you cited within the same paragraph at the beginning of 15.14.1
A postfix expression followed by a ++ operator is a postfix increment expression. The result of the postfix expression must be a variable of a numeric type, or a compile-time error occurs. The type of the postfix increment expression is the type of the variable. The result of the postfix increment expression is not a variable, but a value.

The key difference between the two sentences in red is that the first refers to a posfix expression, while the second refers to a postfix increment expression. Look again at the very first sentence of the quote - those are two different things. In the case of "x++", "x" by itself is a postfix expression, and "x++" is a postfix increment expression. So "x" must be (and is) a variable of numeric type, and "x++" is not a variable, but a value. Clear?

[This message has been edited by Jim Yingst (edited November 10, 2000).]


"I'm not back." - Bill Harding, Twister
Subha Guhan
Greenhorn

Joined: Nov 06, 2000
Posts: 23
Jim
I removing my rattling post in the light of what you have said.
Subha
mohit joshi
Ranch Hand

Joined: Sep 23, 2000
Posts: 243
Well first of all let me thank you for clearing my doubt. I had posted the same question on certification forum but nobody noticed it.
I must admit that I was not very careful while reading that section. But my longstanding doubt has been cleared, so I must thank Jim again.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: post - pre increment