泛型
public class TTest <T>{
private T c;
public TTest(T c) {
this.c = c;
}
public T getC() {
return c;
}
public void setC(T c) {
this.c = c;
}
public static void main(String[] args) {
TTest<Dog> dog = new TTest<>(new Dog());
dog.setC(new Dog("dog","black"));
Dog c = dog.getC();
System.out.println(c.getColor());
System.out.println(c.getKind());
}
}
网友评论