Is this sentence from an OCP book correct?
A HashSet stores its elements in a hash table, which means the keys are a hash and the values are an Object.
I have created below code snippet:
class A
{
private String s;
public static void main(String[] args) throws NoSuchFieldException, IllegalAccessException {
HashSet<A> elems = new HashSet<>(Set.of(new A("abc"), new A("cba"), new A("a")));
Field field = elems.getClass().getDeclaredField("map");
field.setAccessible(true);
HashMap privateMap = (HashMap) field.get(elems);
}
public A(String s)
{
this.s = s;
}
}
And as a result I retrieved the following HashMap:
It looks like it's the object itself being a key in the HashMap instead of its hash being the key. Is there an error in the book or am I looking at something irrelevant?