• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

why map interface do not extend Collection interface though it is a part of Collection framework

 
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,

I want to ask that though Map interface is a part of Collection framework but still it do not extends Collection interface.

Why is it so.

Regards,
Ajay Mittal
 
Author and all-around good cowpoke
Posts: 13078
6
  • Likes 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Exactly how would you have a Map implement the methods of Collection?

For example, what would add( Object x ) mean since a Map needs both a key and a value?

Bill
 
Ranch Hand
Posts: 203
Eclipse IDE Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Folks,
Yeah but is this is the only technical reason that why map is not included..??
 
Sheriff
Posts: 67752
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What other reason would be needed?
 
Ranch Hand
Posts: 608
Firefox Browser Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The Collection Interface has nothing to do with the Collection Framework (well it does, but that's other point). They just happen to share a name.

Collection framework = Collection Interface + Map Interface + possible future interfaces.

For e.g. consider 'Table' - in Google Guava - if something like that or a Tuple ever get added to Collection Framework it most probably would have a new Interface.

Probably someone should have tried using a different name for the 'Collection Interface' or probably the Map is a later addition to the Collection framework and the folks an 'Sun' decided not to rename the framework to Collection-Map framework!

Well let me leave you a questions - why is Java called Java when it has nothing to do with Java?
 
ajay mittal
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,

Thanks a lot all for your opinions and i do rely on it. But is this the only reason for not extending the Collection interface. In the next versions of jdk ,they could even make a interface Map that extends Collection interface and have it's own methods also as put(key,value).
I think there are some more reasons we need to peep through.

Ajay Mittal
 
lowercase baba
Posts: 13091
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don't think you really understand what it means to extend an interface.

BY DEFINITION, if a class extends an interface, it MUST implement each and every method in said interface. The Collections interface has a method, as William pointed out, that looks like this:

add(Object X)

Even if there were a "interface Map extends Collections", anything that implemented that interface would still have to have an "add (Object X)", regardless of what other new methods were declared. And a Map simply cannot meet this requirement.
 
Bartender
Posts: 15737
368
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
And another thing, the point of the Collection interface is that it's generic. A Map is *not* a collection of just anything. A Map is a collection of key-value pairs. That's a very specific restriction, and so it makes no sense to let it extend the generic collection interface.
 
roses are red, violets are blue. Some poems rhyme and some are a tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic