wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes Interfaces in collections framework Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Interfaces in collections framework" Watch "Interfaces in collections framework" New topic
Author

Interfaces in collections framework

Pratik D mehta
Ranch Hand

Joined: Jul 29, 2010
Posts: 121

My question is

Interface Set has method add(E e) and it extends interface Collection.
Interface Collection also has method add(E e)
So why do we need the same method in interface Set , since it already extends interface Collection .
What is the purpose ?
I am stuck with that


Understanding is Everything - Peter Lord
Wouter Oet
Saloon Keeper

Joined: Oct 25, 2008
Posts: 2700

If you compare the javadoc of those interfaces you'll see a differences. The Set interface defines a more specified contract.


"Any fool can write code that a computer can understand. Good programmers write code that humans can understand." --- Martin Fowler
Please correct my English.
Pratik D mehta
Ranch Hand

Joined: Jul 29, 2010
Posts: 121

Wouter Oet wrote:If you compare the javadoc of those interfaces you'll see a differences. The Set interface defines a more specified contract.


Yes I understand that but it is an interface , so does it matter that it tells about no duplicate elements can be added and so on.
It does not implement anything .
So what is the purpose.
Matthew Brown
Bartender

Joined: Apr 06, 2010
Posts: 4372
    
    8

The purpose is to tell developers what the method should do.

If you implement your own Set, it can't make you implement it so that it doesn't allow duplicate elements. All it can do is tell you what the method should do. If you don't follow the contract it specifies, you're going to cause problems.
Pratik D mehta
Ranch Hand

Joined: Jul 29, 2010
Posts: 121

Thank you matthew and Wouter for the help I got it .
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Interfaces in collections framework