package fft.generics;
//表示ship的类型继承了number的字段
public class Ship<T extends Number> {
private T t;
public Ship(T t){
this.t=t;
}
public void print(){
System.out.println(t.getClass().getName());//打印出这个方法的名称
}
public static void main(String[] args) {
Ship<Integer> s1 = new Ship<Integer>(3);
s1.print();
Ship<Float> s2 = new Ship<Float>(new Float(3.26));
s2.print();
Ship<Double> s3 = new Ship<Double>(new Double(3.26987));
s3.print();
}
}
//表示ship的类型继承了number的字段
public class Ship<T extends Number> {
private T t;
public Ship(T t){
this.t=t;
}
public void print(){
System.out.println(t.getClass().getName());//打印出这个方法的名称
}
public static void main(String[] args) {
Ship<Integer> s1 = new Ship<Integer>(3);
s1.print();
Ship<Float> s2 = new Ship<Float>(new Float(3.26));
s2.print();
Ship<Double> s3 = new Ship<Double>(new Double(3.26987));
s3.print();
}
}