Page 1 of 1

About Question enthuware.ocpjp.v7.2.1380 :

Posted: Fri Jun 26, 2015 12:54 pm
by Alexey Berezkin
Why the first option incorrect? Please try the following:

Code: Select all

Map<Map<?, ?>, String> m = new HashMap<Map<?, ?>, String>();
m.put(m, "value");
System.out.println(m);
The output is:

Code: Select all

{(this Map)=value}
You see, this is considered even a special case and properly handled in AbstractMap.toString().

Re: About Question enthuware.ocpjp.v7.2.1380 :

Posted: Sat Jun 27, 2015 10:27 pm
by admin
Well, as per JavaDoc API description of Map
The behavior of a map is not specified if the value of an object is changed in a manner that affects equals comparisons while the object is a key in the map. A special case of this prohibition is that it is not permissible for a map to contain itself as a key.