我在oracle网站上找到了以下问题和答案
类型擦除后,以下类转换为什么?
public class Pair<K, V> {
public Pair(K key, V value) {
this.key = key;
this.value = value;
}
public K getKey(); { return key; }
public V getValue(); { return value; }
public void setKey(K key) { this.key = key; }
public void setValue(V value) { this.value = value; }
private K key;
private V value;
}
Run Code Online (Sandbox Code Playgroud)
回答:
public class Pair {
public Pair(Object key, Object value) {
this.key = key;
this.value = value;
}
public Object getKey() …Run Code Online (Sandbox Code Playgroud)