Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Definite Assignment in JLS not clear - Help  RSS feed

 
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
Boost this thread!