Re: HashMap get/put
Stefan Ram wrote:
Peter Duniho <NpOeStPeAdM@NnOwSlPiAnMk.com> writes:
In that case, apparently it can't. For better or worse, in Java they
have apparently decided that it's okay for two objects to test as equal
to each other even if they aren't the same type. Specifically, one can
write similar overrides to equality in other languages/frameworks, but
it's frowned upon as a very poor practice, and is not found in the
language library itself.
This might be intended for value objects.
Do you also dislike
public class Main
{ public static void main( final java.lang.String[] args )
{ java.lang.System.out.println( 7 == 7.0 );
java.lang.System.out.println( 'A' == 65 ); }}
true
true
?
I'm not sure that is the same case, because 7 is assignment convertible
to double, and 'A' is assignment convertible to int.
Even if Map's get had been defined as get(K) instead of get(Object), any
expression that is assignment convertible to K would be allowed as the
get parameter. For example, an ArrayList reference could still be used
in the get method of a HashMap<List,String>.
The controversial case is when the get parameter is not assignment
convertible to K, as in my ArrayList parameter for a HashMap<Stack,String>.
Patricia