Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Quick question about interfaces

 
Rick Katka
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • 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
 
Rikko Verrijzer
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • 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
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
  • 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"?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic