Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Question on "Final" modifier.

 
Sanjeev BhimaRao
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Is it possible in any scenario to manipulate or change the value of a variable marked "final" ? I believe it is not possible. Please let me know if someone knows about a possible scenario where this might be possible.
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No it's not possible.
 
Shaan Shar
Ranch Hand
Posts: 1249
Java Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Sanjeev BA:
Hi,
Is it possible in any scenario to manipulate or change the value of a variable marked "final" ? I believe it is not possible. Please let me know if someone knows about a possible scenario where this might be possible.


Ofcourse you cann't change the reference of final variables. But you can change the value of a final Object. like this.



Hope it helps you.
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And we're back to a discussion on reference/value

So you cannot change the value of a reference, nor the value of a primitive, marked as final. Of course, you can access the content of a reference.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic