How does java type inference work?
Can someone please explain how the following syntax works? public static <K, V> HashMap<K, V> getMap(){ return new HashMap<K, V>(); } As in, if this method was implemented in a non instantiable util class of my own this can be used as a static factory method to create map instances, right? Map<Integer, String> myMap = MyUtil.getMap(); would then return a new HashMap with Integer keys and String values for its entries, am I right? If so, how are the types of the key and entry of map being realized by the compiler and VM? I would really appreciate if someone could explain how Java does this. You