• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Quick question about interfaces

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm implementing a textparsing application. My questions arises that if I have an interface class called DocumentComponent and it contains an ArrayList of components that are initialized in the constructor and a few methods such as add, remove, and count.
Will I be able to use the ArrayList of components in the overloaded classes such as sentence and word?
Thanks in advance!
Rick J. Katka
 
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Rick,
If you define an inteface you should know that all variables defined in that interface are final. That means that you can use the values(!!!), but not change them.
note that a value is something different for an object than for a primitive. Primitives values of those like int, byte, boolean etc. are unchangable. However, a object value is the refference to an object, not its inner values. This means that an object can not be replaced with any other reference, but its methods like add(), get(), count() etc. can be called and used to change its inner values.
So its possible to add new elements into your arraylist even though your arraylist is final. However you can't replace the arraylist with a new instance (filled with whatever you like).

Hope this helps?
Rikko
 
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Will I be able to use the ArrayList of components in the overloaded classes such as sentence and word?
What do you mean by "overloaded class"?
reply
    Bookmark Topic Watch Topic
  • New Topic