[Logo]
Forums Register Login
interface overrides in Java Collection API
In Java Collection API framework, the Collection interface has defined a set of methods, e.g. size, isEmpty etc. There are 3 other interfaces which are subinterfaces of it, Set, List and Queue.

My question is, I notice in the Set and List interface definition, all the methods defined in Collection are redeclared again. But not the Queue interface. Aren't anything defined in Collection automatically available for all its sub interfaces and you practically don't need to redeclare it in List or Set?

Thanks!
They don't need to be redeclared for the sake of the methods being available, but in some of these cases it's the API documentation that is "overridden".

For instance, Set's add method specifies that an element will only be added if not present, whereas List's add method specifies that the element needs to be added at the end of the list.

Some methods don't make sense though, like size and isEmpty.
Rob, Thanks so much! This really helps.
All of life is a contant education - Eleanor Roosevelt. Tiny ad:
Thread Boost - a very different sort of advertising
https://coderanch.com/t/674455/Thread-Boost-feature


This thread has been viewed 541 times.

All times above are in ranch (not your local) time.
The current ranch time is
Apr 27, 2018 02:57:45.