dcsimg
final ArrayList
2 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Anonymous
Posted On:   Wednesday, December 14, 2005 06:20 AM

Hi

i want clear idea


if iam declaring ArrayList as final then what happed.


Can increase the size of arraylist or not

Re: final ArrayList

Posted By:   Jani_Kaarela  
Posted On:   Thursday, December 15, 2005 04:23 AM

Can increase the size of arraylist or not



A final mutable object (ie. one with methods that change it's state) isn't nearly as "final" as you'd easily expect. The final keyword only prevents re-assigning the variable and thus ensures, that the variable will always refer to the same object. You can still manipulate the object freely.




If you want to create an unmodifiable List, use Collections.unmodifiableList(java.util.List) to create a wrapper that prevents modifications to the list.

Re: final ArrayList

Posted By:   WarnerJan_Veldhuis  
Posted On:   Wednesday, December 14, 2005 07:34 AM

What happened when you tried??? I would say it's ok, since "final" says, the variable pointing to the ArrayList cannot change. It says nothing about the behaviour of an object.
About | Sitemap | Contact