Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 7 of 7

Thread: Why List interface is implemented multiple time in same hierarchy

  1. #1
    Junior Member
    Join Date
    Jan 2014
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Why List interface is implemented multiple time in same hierarchy

    I have seen hierarchy in java for collection framework.
    List-AbstractList
    AbstractList-ArrayList
    List - ArrayList
    AbstractList - ArrayList
    Here List is implemented in AbstractList and List is also implemented by ArrayList.

    Why this hirarchy is created in java? Is there any specific reason for this?


  2. #2
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,520
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: Why List interface is implemented multiple time in same hierarchy

    To give the programmer the desired/needed flexibility and functionality. What's the point of your question, or is this a quiz/test/exam question? How will knowing this make you a better programmer?

  3. #3
    Junior Member
    Join Date
    Jan 2014
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Why List interface is implemented multiple time in same hierarchy

    This is general question faced when i was reading source of java
    if array list is not implementing List interface the below statement is possible for inheritance.
    List<String> s= new ArrayList<String>();
    It seems me one reason behind implementing List interface in ArrayList that it forces programmer to implement these methods otherwise it doesn't seem any reason behind this

  4. #4
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,520
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: Why List interface is implemented multiple time in same hierarchy

    See if this discussion answers your question. There are several others like it, saying essentially the same thing. If you still have questions, please come back.

  5. #5
    Forum VIP
    Join Date
    Jul 2010
    Posts
    1,676
    Thanks
    25
    Thanked 329 Times in 305 Posts

    Default Re: Why List interface is implemented multiple time in same hierarchy

    I think he's asking: why does ArrayList explicitely implement the List interface if the List interface is already implicitly inherited when AbstractList is extended?
    NOTE TO NEW PEOPLE LOOKING FOR HELP ON FORUM:

    When asking for help, please follow these guidelines to receive better and more prompt help:
    1. Put your code in Java Tags. To do this, put [highlight=java] before your code and [/highlight] after your code.
    2. Give full details of errors and provide us with as much information about the situation as possible.
    3. Give us an example of what the output should look like when done correctly.

    Join the Airline Management Simulation Game to manage your own airline against other users in a virtual recreation of the United States Airline Industry. For more details, visit: http://airlinegame.orgfree.com/

  6. #6
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,520
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: Why List interface is implemented multiple time in same hierarchy

    Thanks for explaining. I'm often thick.

    Here's one discussion directly related to the OP's question (as clarified), but there other related/tangential discussions. I don't know that anyone other than the language designers can say for sure that THIS is the reason, but the answer at the link was apparently accepted as reasonable.

  7. #7
    Junior Member
    Join Date
    Jan 2014
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Why List interface is implemented multiple time in same hierarchy

    discussion at link java - Why does ArrayList have "implements List"? - Stack Overflow doesn't seem any valid reason if this is to increase tracability of the inheritance structure so this can also be
    public class ArrayList<E> extends AbstractList<E>
    implements List<E>,Collection<E>, RandomAccess, Cloneable, java.io.Serializable
    Here I have added Collection<E> extra also.
    And also just for sake of tracability I think no one is going to make the the inheritance hierarchy complex.
    I think there is some another reason for this. if i check the hashset it's also using the same way as ArrayList

    public abstract class AbstractSet<E> extends AbstractCollection<E> implements Set<E>
    public class HashSet<E>
    extends AbstractSet<E>
    implements Set<E>, Cloneable, java.io.Serializable

Similar Threads

  1. Replies: 0
    Last Post: October 4th, 2013, 08:34 PM
  2. Replies: 3
    Last Post: July 11th, 2012, 11:37 PM
  3. Need more help, this time requiring the Comparable interface
    By Mellowhype in forum What's Wrong With My Code?
    Replies: 4
    Last Post: November 14th, 2011, 11:58 PM
  4. "Static method cannot hide instance method from implemented Interface"
    By Gthoma2 in forum What's Wrong With My Code?
    Replies: 4
    Last Post: June 21st, 2011, 03:03 AM
  5. Multiple instances of linked list
    By thedolphin13 in forum What's Wrong With My Code?
    Replies: 5
    Last Post: October 11th, 2010, 07:48 PM