//练习泛型 public class TestFanx { public static void main(String[] args) { Apple1<Integer> a1 = new Apple1<>();//a1为Integer //Apple1<String> a2 = new Apple1<String>();继承了Number只能接受Number Apple1<Double> a2 = new Apple1<Double>(); a1.setSize(10);//设置a1.size System.out.println(a1.getSize());//输出a21.size a2.setSize(12.25); System.out.println(a2.getSize()); } } class Apple1<T extends Number>{//继承了Number 设置泛型的上限 private T size; public T getSize() { return size; } public void setSize(T size) { this.size = size; } }