Solved

map interface methods

Posted on 2016-08-05
3
51 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
3 Comments
 
LVL 14

Expert Comment

by:CPColin
Comment Utility
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
Comment Utility
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 26

Accepted Solution

by:
dpearson earned 500 total points
Comment Utility
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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

If you’re thinking to yourself “That description sounds a lot like two people doing the work that one could accomplish,” you’re not alone.
Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.

762 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

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now