Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Java > Java and JDK > Pro Java
|
Pro Java Expert level Java questions not about a specific book. Please indicate your version.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Pro Java section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old December 27th, 2007, 08:26 PM
Registered User
 
Join Date: Dec 2007
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default HashMap's Map.Entry interface

Hello and good day to you all!

I was confused about some Map theory and was hoping someone could help me sort it out.

I have been reading the older 1.4 version of Horton’s Beginning Java, and am on the section about HashMaps. Now, he talks about one can get a Set of entries from the HashMap using the entrySet() method.

Now, here’s the rub. The contents of this set are objects of type Map.Entry. But here is what threw me:

“The key/object pairs are of type Map.Entry because Entry is an interface declared within the Map interface.”

Interface?! But Horton says in Chapter 06:

“The declaration of the class as abstract is mandatory when you don't implement all of the methods that are declared in an interface.”

It seems that Map.Entry is abstract, since it appears that the five methods contained in the class (http://java.sun.com/j2se/1.4.2/docs/...Map.Entry.html) have [u]not</u> been implemented. Or have they…

In Horton’s HashMap section, Horton refers to the Set elements as Map.Entry objects.

In addition, look at this code from Oracle (http://www.oracle.com/technology/pub...les/maps1.html) :

Iterator keyValuePairs1 = aMap.entrySet().iterator();
for (int i = 0; i < mapsize; i++)
{
  Map.Entry entry = (Map.Entry) keyValuePairs1.next();
  Object key = entry.getKey();
  Object value = entry.getValue();
  ...
}

Again, we use an interface to create an [u]object</u>? So…

** Are these examples assuming the five methods are already implemented?

** If not, how can we create an object out of a partial interface?

** If so, does the user typically code the implementation? Or does Sun do so in their standard HashMap class? If Sun has done so, do the API docs indicate this anywhere?

** Could the five methods be overridden by extending HashMap?

Much obliged!
-gabe

 
Old January 3rd, 2008, 10:19 AM
Friend of Wrox
 
Join Date: Mar 2007
Posts: 373
Thanks: 0
Thanked 1 Time in 1 Post
Default

First of all Map is an interface and it has a sub interface Entry in it. All the classes implementing this Map interface like HashMap, etc has the implementation for the Entry interface also. You can see this implementation in the source code of java.


- Rakesh





Similar Threads
Thread Thread Starter Forum Replies Last Post
how to map a url to another? worldcrafter Apache Tomcat 0 April 2nd, 2008 06:19 PM
Heat Map over Google Map ajit Javascript 0 March 7th, 2008 09:01 AM
Site Map mallikalapati ASP.NET 2.0 Basics 1 February 9th, 2008 02:56 PM
Map Path??? thetwai C# 3 April 5th, 2007 07:26 AM
Image Map? sporkman43 VB.NET 2002/2003 Basics 2 July 1st, 2004 10:59 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.