How does java type output work?

Can someone explain how the following syntax works?

public static <K, V> HashMap<K, V> getMap(){
    return new HashMap<K, V>();
}

As in the case where this method was implemented in an uninteresting utility class, I can use it as a static factory method to create map instances, right?

Map<Integer, String> myMap = MyUtil.getMap();

then will return a new HashMap with integer keys and String values ​​for its records, right? If so, how are the key types and card input implemented by the compiler and VM?

I would really appreciate it if anyone could explain how Java does this.

+4
source share
1 answer

, Java . Java , , . , . , , , , , .

" ", , , Java API documentation Java ( ).

- , (, ). , " , ". K Integer V String , .

+3

Source: https://habr.com/ru/post/1598643/


All Articles