According to Java doc for weakhashmap:
"This class is intended primarily for use with key objects whose equals methods test for object identity using the == operator. Once such a key is discarded it can never be recreated, so it is impossible to do a lookup of that key in a WeakHashMap"
Does this mean that if we use an objectA as key for entry 0 in the weakhashmap, and later we remove that entry testMapHashWeak.remove(objectA);
we can not use the same key objectA
for another entry? Cause I have made an small test and I can do it:
public void test4WeakHashMap(WeakHashMap<B, String> testMapHashWeak) {
B objectB = new B();
String sTest = "hola";
System.out.println("1st time - key&value inserted ->"+objectB+","+sTest);
testMapHashWeak.put(objectB, sTest);
System.out.println("Get element 1st time-> "+testMapHashWeak.get(objectB));
testMapHashWeak.remove(objectB);
//Insert 2nd time
System.out.println("2st time - key&value inserted ->"+objectB+","+sTest);
testMapHashWeak.put(objectB, sTest);
System.out.println("Get element 2nd time-> "+testMapHashWeak.get(objectB));
}
Being the output:
1st time - key&value inserted ->B@634e3372,hola
Get element 1st time-> hola
2st time - key&value inserted ->B@634e3372,hola
Get element 2nd time-> hola