class Gun<T,K>{
private T talk;
private K kit;
public T getTalk() {
return talk;
}
public void setTalk(T talk) {
this.talk = talk;
}
public K getKit() {
return kit;
}
public void setKit(K kit) {
this.kit = kit;
}
}
public class GenericDemo02 {
public static void main(String[] args) {
Gun<String,Integer> g = new Gun<>();
g.setTalk("谈谈心");
g.setKit(233);
System.out.println(g.getTalk()+" "+g.getKit());
}
}
类实例化以后,传入值的时候一定要与实例中泛型相对应
Jav笔记之泛型(指定多个泛型)
最新推荐文章于 2024-06-02 11:03:56 发布