Inconvertible types; cannot cast ‘int‘ to ‘K‘

Inconvertible types; cannot cast 'int' to '

public static <K,V>  Map<K, V> newMapT(V... objects) {
    Map<K, V> map = new HashMap<>();
    for (V object : objects) {
        map.put((K)1, object);
    }
    return map;
}

Solution:

map.put((K)new Integer(1), object);

Guess you like

Origin blog.csdn.net/x18094/article/details/112978775