In the Java implementation, I found
transient Entry[] table;
which is initiated in constructor as
table = new Entry[capacity];
I know and u
The implementation makes an array of Entry
objects of type
static class Entry implements Map.Entry
without providing generic type parameters (source). This is allowed, but it comes with understanding that the compiler is no longer guarantees type safety. For example, in other places in code you could write
Entry e = table[bucketIndex];
and the compiler will let you do that. If you know for sure that you always set elements of table[]
to null
or Entry
, then you know that the assignment is correct.
The reason this works without a problem is that generic types in Java are implemented through type erasure, i.e. there is no difference at runtime between Entry
objects Entry
and Entry
.