Re: HashMap get/put
Stefan Ram wrote :
ram@zedat.fu-berlin.de (Stefan Ram) writes:
Look at the following example: (...)
final java.util.Map<java.lang.String,java.lang.String> value0
= new java.util.HashMap<java.lang.String,java.lang.String>(); (...)
?value1? has not the type used in the map, yet the ?get? succeeds.
Above, both types were the same after type erasure and were
types of empty containers.
Here is a program with types that differ even after type
erasure and non-empty containers.
Um, I did a bit of editing in your example, removing the packages. For
some reason this makes it easier for me to read...
public class Main
{ public static void main( final String[] args )
{
final ArrayList<String> list0 = new ArrayList<String >();
list0.add( "text" );
final LinkedList<String > list1 = new LinkedList<String >();
list1.add( "text" );
final Map<ArrayList<String>,String> map = new
HashMap<ArrayList<String>,String >();
map.put( list0, "value" );
System.out.println( map.get( list1 ));
}
}
I do not see why this works or why this should work. Maybe because
"text" was added to both list0 and list1?
--
Wojtek :-)