public class Generics1<A> {
private A a;
public void set(A a) {
this.a = a;
}
public A get() {
return a;
}
public <U extends Number> void inspect(U u) {
System.out.println("T: " + a.getClass().getName());
System.out.println("U: " + a.getClass().getName());
}
public static void main(String[] args) {
Generics1<Integer> integerBox = new Generics1<Integer>();
integerBox.set(new Integer(10));
integerBox.inspect(10);
}
}
No comments:
Post a Comment