Results 1 to 3 of 3
Like Tree1Likes
  • 1 Post By muthukrishnan.muthu

Thread: Why both ArrayList and AbstractList are implements List interface?

  1. #1
    Join Date
    Apr 2012
    Posts
    3
    Rep Power
    0

    Question Why both ArrayList and AbstractList are implements List interface?

    Hi All,

    I don't know the reason why the ArrayList & AbstractList classes are implements List interface as the AbstractList classes itseft it implements List interface.


    AbstractList<E> extends AbstractCollection<E> implements List<E> {
    ArrayList<E> extends AbstractList<E>
    implements List<E>, RandomAccess, Cloneable, java.io.Serializable{
    jim829 likes this.

  2. #2
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    4,017
    Rep Power
    6

    Default Re: Why both ArrayList and AbstractList are implements List interface?

    Well, unless there is something subtle that I am unaware of, it looks like a redundant declaration to me. You could still assign an ArrayList object to a List reference even if the ArrayList did not explicitly declare that it implements List. Perhaps others may have a different perspective.

    An afterthought could be that it is simply a way to emphasize that ArrayList implements List (which is very useful to know). So it is somewhat self documenting as opposed to syntactically necessary.

    Jim
    Last edited by jim829; 02-28-2013 at 04:25 PM. Reason: Upon further consideration...
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  3. #3
    wsaryada is offline Senior Member
    Join Date
    Jun 2007
    Location
    Bali, Indonesia
    Posts
    760
    Rep Power
    8

    Default Re: Why both ArrayList and AbstractList are implements List interface?

    As Jim said the reason can be for documentation especially for the generated Javadoc so that the ArrayList will be included as a class that implements the java.util.List interface. And the AbstractList was there to implements some general features shared by the java.util.List implementation to reduce the code duplications.

Similar Threads

  1. Replies: 1
    Last Post: 07-08-2012, 06:23 PM
  2. What about variables? implements Interface > extends
    By Bigfatcat in forum New To Java
    Replies: 8
    Last Post: 01-08-2012, 09:57 AM
  3. Extends a class that implements an interface
    By monocole in forum New To Java
    Replies: 2
    Last Post: 12-27-2011, 04:55 AM
  4. Interface and implements
    By Bored2 in forum New To Java
    Replies: 27
    Last Post: 11-10-2010, 02:08 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •