Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

map interface methods

Posted on 2016-08-05
3
Medium Priority
?
112 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 2000 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

Tech or Treat! - Giveaway

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

Question has a verified solution.

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

Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
We live in a world of interfaces like the one in the title picture. VBA also allows to use interfaces which offers a lot of possibilities. This article describes how to use interfaces in VBA and how to work around their bugs.
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
Suggested Courses

604 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