• Post Reply Bookmark Topic Watch Topic
  • New Topic

What is a final Vector?  RSS feed

 
vijayk kumar
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is the purpose of declaring a Vector as final as,
final Vector v= new Vector(1);
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It means the variable v cannot be modified later to point to a different Vector. This is nice documentation to tell readers you don't intend to change the variable, a useful tip to the compiler that may let it generate more efficient code, and necessary for some inner classes to access the variable.

Note that the variable will always reference the same Vector, but we can still change the Vector itself by adding and removing items.
 
vijayk kumar
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks James!
Please see my next posting.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!