This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How List interface work ?

 
Alvin chew
Ranch Hand
Posts: 834
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi, just wondering , how the List interface work ? i confuse as i know interface forced implemented class to write the method which declared in interface, my concern is

if we have following codes



as shown, how the "add" method from List interface work ? we didn't define the method..what is the hiding part behind ..

thank you very much for your time
[ July 26, 2004: Message edited by: Alvin chew ]
 
Marilyn de Queiroz
Sheriff
Posts: 9059
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ArrayList implements List and overrides the add() method.
 
Alvin chew
Ranch Hand
Posts: 834
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Marilyn, you meant ArrayList already define "add" method ?
 
Mani Ram
Ranch Hand
Posts: 1140
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Alvin chew:
Marilyn, you meant ArrayList already define "add" method ?


Correct. ArrayList is a concreate class which implements the List interface and overrides the add() method(s).
 
Alvin chew
Ranch Hand
Posts: 834
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thank you , mani ...i clear now ....is it possible we can have a look on the code for ArrayList class ?
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sure. Your JDK has a file called src.zip (or possibly src.jar) which contains the source code for most of the Java libraries. (Excluding native methods.) You can upen this with most any unzipping tool (including many file browsers, nowadays) or using

jar -xvf src.zip
 
Alvin chew
Ranch Hand
Posts: 834
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks , jim ...try it now ....
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Alvin, you might like a read of the "How my Dog learned Polymorphism" story in the JavaRanch Campfire Stories.
 
Alvin chew
Ranch Hand
Posts: 834
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thank dirk , reading
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic