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