• Post Reply Bookmark Topic Watch Topic
  • New Topic

A question on LinkedHashMap  RSS feed

 
manish ghildiyal
Ranch Hand
Posts: 136
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

As I was looking into implementation of LinkedHashMap, it extends HashMap.
My question is that why does it need to implement Map interface as HashMap also implements Map interface.
If class A implements interface I, and class B extends class A ,doesn't B implicitly implements I too?

With regards
Manish
 
fred rosenberger
lowercase baba
Bartender
Posts: 12563
49
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've not looked at the implementation details, but my guess would be that a LinkedHashMap may need to implement the methods differently than a Hashmap.
 
Paweł Baczyński
Bartender
Posts: 2083
44
Firefox Browser IntelliJ IDE Java Linux Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Declaring that LinkedHashMap implements Map is redundant.
There are more examples of redundancy in java. For example all methods in an interface are public abstract.

So those two are the same:
 
manish ghildiyal
Ranch Hand
Posts: 136
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Pawel, yeah redundancy seems to be a plausible reason here.

Thanks for input.

Manish
 
Winston Gutkowski
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
manish ghildiyal wrote:Hi Pawel, yeah redundancy seems to be a plausible reason here.

I'd also say that documentation is another. It's important for someone to know that LinkedHashMap implements Map - in fact it's probably the MOST important thing to know - and adding it redundantly allows someone to see it without having to search superclasses.

Winston
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!