• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

Why doesn't 'final String[][] ....' make it final?????

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I declared a 2-dim array of strings as final. However, I'm able to modify the contents of the array.
1. Why??
2. How can I make the contents final?
Thank you


[ Jess adjusted the line breaks so the page won't scroll horizontally ]
[ February 06, 2003: Message edited by: Jessica Sant ]
 
Ranch Hand
Posts: 401
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The fields of the array are not final, though the array isself is.
In a real-life situation, you'd make a cat object w/final fields.
 
Sheriff
Posts: 4313
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
the way Garrett wrote your class is a much more object oriented way of doing things. To make it even MORE so -- and to get some encapsulation goin' you'd mark all the Attributes of the cat glass private and create getters/setters for those attributes.
As for the reason why you're able to change the contents of your final string array... read on.
An array is really an object. Even an array of primitives is an object. So, just like when you mark any old object as final, that means that you can't change what object that variable refers to -- (that's what final does to reference variables) however you can change the state of the object it refers to.
So... check out this code snippet:

does that help?
[ February 06, 2003: Message edited by: Jessica Sant ]
 
reply
    Bookmark Topic Watch Topic
  • New Topic