Just came up upon a very strange behavior of Java HashMap. The map has the Long type of keys, but when I access them passing an int key, there is no autocast, instead the get() method returns null as if the key does not exist! Why Java does no proper auto casting from int to long in this case?
Just came up upon a very strange behavior of Java HashMap. The map has
Share
Map.get() and remove() accept any object. Your
intis being auto-boxed toIntegerIt doesn’t know what you meant to write is
map.get((Long) (long) intValue)ormap.get((long) intValue)If you are using primitive types, rather than objects, you can try TLongObjectHashMap which does convert
inttolong(not the wrappers)