wood burning stoves 2.0*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Definite Assignment in JLS not clear - Help 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 "Definite Assignment in JLS not clear - Help" Watch "Definite Assignment in JLS not clear - Help" New topic
Author

Definite Assignment in JLS not clear - Help

R Arun
Ranch Hand

Joined: Apr 20, 2002
Posts: 33
From the JLS

16.1.8 Operators ++ and --
V is definitely assigned after ++a, --a, a++, or a-- iff either a is V or V is definitely assigned after the operand expression.
V is definitely unassigned after ++a, --a, a++, or a-- iff a is not V and V is definitely unassigned after the operand expression.
V is [un]assigned before a iff V is [un]assigned before ++a, --a, a++, or a--.

However this does not compile:
Jose Botella
Ranch Hand

Joined: Jul 03, 2001
Posts: 2120
I think JLS 15.5.1 takes precedence:

A variable that is declared final cannot be incremented, because when an access of a final variable is used as an expression, the result is a value, not a variable. Thus, it cannot be used as the operand of a prefix increment operator.

The code compile if final is left out. However preincrementing a final variable gives an error either in a method, constructor or static block.


SCJP2. Please Indent your code using UBB Code
 
 
subject: Definite Assignment in JLS not clear - Help
 
Similar Threads
definitely assigned after switch
try catch finally blocks
A funny question,see it!!
Increment Operator
definite assignment