package edu.learn.foundation;
public class Test {
public static void main(String[] args) {
LimitClass<Dog> dog = new LimitClass<Dog>();
LimitClass<Animal> animal = new LimitClass<Animal>();
//LimitClass<Fruit> fruit = new LimitClass<Fruit>(); 报错
}
}
1. 范型类实例化时,只可以使用aninal 和 dog,
2. 范型类实例化时,不可以使用fruit, 因为fruit没有继承aninal
3. 示例:
package edu.learn.foundation;
public class Animal {
}
package edu.learn.foundation;
public class Dog extends Animal {
}
package edu.learn.foundation;
public class Fruit {
}
package edu.learn.foundation;
public class LimitClass<T extends Animal> {
}