/*指定多个泛型类型*/
class Notepad<K,V>{ //指定多个泛型类型
private K key;
private V value;
public K getKey() {
return key;
}
public void setKey(K key) {
this.key = key;
}
public V getValue() {
return value;
}
public void setValue(V value) {
this.value = value;
}
}
public class GenericsDemo2 {
public static void main(String[] args) {
// TODO Auto-generated method stub
Notepad<String,Integer> np = null; //指定多个泛型类型
np = new Notepad<String, Integer>();
np.setKey("我去");
np.setValue(39);
System.out.println("Key:"+np.getKey()+", Value:"+np.getValue());
}
}
class Notepad<K,V>{ //指定多个泛型类型
private K key;
private V value;
public K getKey() {
return key;
}
public void setKey(K key) {
this.key = key;
}
public V getValue() {
return value;
}
public void setValue(V value) {
this.value = value;
}
}
public class GenericsDemo2 {
public static void main(String[] args) {
// TODO Auto-generated method stub
Notepad<String,Integer> np = null; //指定多个泛型类型
np = new Notepad<String, Integer>();
np.setKey("我去");
np.setValue(39);
System.out.println("Key:"+np.getKey()+", Value:"+np.getValue());
}
}