I have a class named InstanceClass
as follows:
package trials;
public class InstanceClass<T> {
private T num;
public void calculate() {
System.out.printf("%s", num);
}
public T getNum() {
return num;
}
public void setNum(T num) {
this.num = num;
}
public InstanceClass(T num) {
super();
this.num = num;
}
}
and Trial
class in which the main method located as follows:
package trials;
public class TrialClass {
public static void main(String[] args) {
InstanceClass<Integer> my=new InstanceClass<>(2);
InstanceClass<InstanceClass<Integer>> x=new InstanceClass<>(my);
prt(x.getNum());
}
public static <T extends InstanceClass<Integer>> void prt(T q) {
System.out.printf("%s%n",q.getNum());
q.calculate();
}
}
So, I want to know why can't we simply use <T> instead of <T extends InstanceClass<Integer>> in the method prt's declaration.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…