指定多个泛型类型

来源:互联网 发布:淘宝天天特价规则 编辑:程序博客网 时间:2024/06/06 01:40
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 Test {


public static void main(String[] args) {


Notepad<String,Integer> t = null;
t = new Notepad<String,Integer>();
t.setKey("张三");
t.setValue(30);
System.out.println(t.getKey()+"---"+t.getValue());
}


}

运行结果:

张三---30

0 0
原创粉丝点击