• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Bear Bibeault
  • Knute Snortum
  • Liutauras Vilda
Sheriffs:
  • Tim Cooke
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Ron McLeod
  • Ganesh Patekar
  • salvin francis
Bartenders:
  • Tim Holloway
  • Carey Brown
  • Stephan van Hulst

interface overrides in Java Collection API  RSS feed

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
 
Sheriff
Posts: 21557
100
Chrome Eclipse IDE Java Spring Ubuntu VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Rui Wang
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rob, Thanks so much! This really helps.
 
That which doesn't kill us makes us stronger. I think a piece of pie wouldn't kill me. Tiny ad:
Programmatically Create PDF Using Free Spire.PDF with Java
https://coderanch.com/wiki/703735/Programmatically-Create-PDF-Free-Spire
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!