Solved

map interface methods

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
eclipse java  build path 6 44
"Black Box" Testing of Control System Software 2 25
expectj telnet failing 5 26
How to write an English digest paper 6 23
This is an explanation of a simple data model to help parse a JSON feed
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

910 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

16 Experts available now in Live!

Get 1:1 Help Now