Reputation: 1
I am not sure if it's been asked. I am fairly new to hashtables and was wondering about something about the inner class.
I was looking at the hashtable API and it had:
static class Entry<K,V> implements Map.Entry<K,V> { }
my question is: Is it possible to implement the inner class if it was just:
class Entry{ }
Would that be possible?
Upvotes: 0
Views: 80
Reputation: 1500505
Well that would be a valid nested class, but it wouldn't implement Map.Entry
, so it couldn't be used for the Map
methods which require Map.Entry
, such as entrySet()
.
The reason it's declared with the static
modifier is that a HashMap.Entry
instance doesn't need to know which HashMap
it's part of, so there's no benefit in having that extra implicit reference.
Upvotes: 3