• Post Reply Bookmark Topic Watch Topic
  • New Topic

Adding elements to final vector  RSS feed

 
Priya Venkatesan
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As far I understand, when a variable is declared as final its value cant be changed.I have created a final vector and I can add elements to this. Can anyone explain as to why I am able to add elements to this final vector?
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Objects are never final -- variables. A variable is a reference to an object. You can't change that reference to point to another object -- but you can modify the object,
 
Tony Morris
Ranch Hand
Posts: 1608
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First, you need to know the difference between a reference and an object here

Next, you need to know that the final modifier, as you have described it, applies to references, not objects.
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
We also have a Pass by Reference Please story in the JavaRanch Campfire.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!