Question about java.util.Set

Discussion in 'Java' started by Zhao, Oct 24, 2003.

  1. Zhao

    Zhao Guest

    I noticed that java.util.Set extends java.util.Collection and
    all the abstract methods of Collection is redeclare in java.util.Set.

    Why? It is not necessary since java.util.Set inheritant all this methods
    already, why do we need to redeclare them? Similar codes appear in other
    Collection interfaces like List.

    thanks

    Zhao
     
    Zhao, Oct 24, 2003
    #1
    1. Advertising

  2. Zhao wrote:
    > I noticed that java.util.Set extends java.util.Collection and
    > all the abstract methods of Collection is redeclare in java.util.Set.
    >
    > Why? It is not necessary since java.util.Set inheritant all this methods
    > already, why do we need to redeclare them? Similar codes appear in other
    > Collection interfaces like List.


    Indeed this is technically unnecessary but was probably done in order to be
    able to give more specific javadoc comments in the derived interfaces.
     
    Michael Borgwardt, Oct 24, 2003
    #2
    1. Advertising

  3. Zhao wrote:

    > I noticed that java.util.Set extends java.util.Collection and
    > all the abstract methods of Collection is redeclare in java.util.Set.
    >
    > Why? It is not necessary since java.util.Set inheritant all this methods
    > already, why do we need to redeclare them? Similar codes appear in other
    > Collection interfaces like List.


    Michael's response is pretty good, but why not read what Sun itself has
    to say about the matter in Set's API docs:

    The Set interface places additional stipulations, beyond those inherited
    from the Collection interface, on the contracts of all constructors and
    on the contracts of the add, equals and hashCode methods. Declarations
    for other inherited methods are also included here for convenience. (The
    specifications accompanying these declarations have been tailored to the
    Set interface, but they do not contain any additional stipulations.)


    Similar statements appear in the API docs of the other interfaces of the
    collections framework.


    John Bollinger
     
    John C. Bollinger, Oct 24, 2003
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Michael T. Peterson
    Replies:
    2
    Views:
    757
    Michael T. Peterson
    Sep 9, 2003
  2. Hendrik Maryns

    Extending java.util.Set

    Hendrik Maryns, Feb 15, 2006, in forum: Java
    Replies:
    11
    Views:
    5,421
    Mike Schilling
    Feb 17, 2006
  3. Robert Mark Bram
    Replies:
    0
    Views:
    624
    Robert Mark Bram
    Apr 30, 2007
  4. Santha
    Replies:
    0
    Views:
    1,111
    Santha
    Jan 14, 2010
  5. J.Cottingim

    set Bad variable type - SNMP::Util set

    J.Cottingim, Jul 3, 2007, in forum: Perl Misc
    Replies:
    0
    Views:
    119
    J.Cottingim
    Jul 3, 2007
Loading...

Share This Page