Solved

map interface methods

Posted on 2016-08-05
3
67 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
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 26

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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
web application structure 18 77
Bartender Integration Builder 3 18
hibernate example using maven 12 42
Java: How do I open the default windows program for a given file type 3 28
A short article about a problem I had getting the GPS LocationListener working.
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

770 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