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

regarding final....

 
Guru dhaasan
Ranch Hand
Posts: 126
Java Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In p:202 of Head first Servlets & JSP book, we have the following para.

"...and since you are a Java programmer, you know that even a final variable still be manipulated unless its immutable"

Can anyone explain how a final can be manipulated ?
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Recall your SCJP memories.

rancher is final, but its content can still be manipulated.
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Consider the following:



You would expect 'final' to prevent the value of a variable to change, but it just prevents it from changing to a new instance. If the value of the instance can be altered (ie it is not immutable) then the value returned by the final instance can change, even if the instance does not.

Dave
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic