Solved

map interface methods

Posted on 2016-08-05
3
90 Views
Last Modified: 2016-08-07
Hi,
I wonder why Map interface has equals() and hashCode() methods again in Entry  method as they are already there before?

[i]boolean
equals(Object
paramObject);
int
hashCode();[/i]
public
static
abstract
interface
[b]Entry[/b]<K,
V>
{
K
getKey();
V
getValue();
V
setValue(V
paramV);
boolean
equals(Object
paramObject);
int
hashCode();
}

Open in new window


please advise
0
Comment
Question by:gudii9
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 14

Expert Comment

by:CPColin
ID: 41744325
It's probably so the Javadocs for those methods can clarify that implementations should be looking at both the key and the value.
0
 
LVL 7

Author Comment

by:gudii9
ID: 41745118
It's probably so the Javadocs for those methods can clarify that implementations should be looking at both the key and the value.
if you see below javedocs for map interface that also has equals and hascode() methods as attached.

http://docs.oracle.com/javase/8/docs/api/java/util/Map.html

my question is why below Map.Entry as below has same methods again

http://docs.oracle.com/javase/8/docs/api/java/util/Map.Entry.html
hashCodeMap.png
equalsMap.png
0
 
LVL 28

Accepted Solution

by:
dpearson earned 500 total points
ID: 41746282
If I understand your question correctly it's because they are two different things.

Map.equals() is for deciding if 2 maps are the same.  That means they contain *all* of the same entries.

Map.Entry.equals() is for deciding if 2 entries in a map are the same.

It's the difference between deciding if two libraries contain all of the same books (Map.equals) or if two books in a library are copies of the same book (Map.Entry.equals).

Doug
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article will inform Clients about common and important expectations from the freelancers (Experts) who are looking at your Gig.
Make the most of your online learning experience.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Simple Linear Regression

717 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question