This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Definite Assignment in JLS not clear - Help

 
R Arun
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2120
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic