public class GenericsTest {
public static void (String[] args) {
Box
<Integer> intergerBox = new Box
<Integer>(); // suppose only store integers
integerBox.add(456);
Integer oneInteger=integerBox.get();
System.out.println(oneInteger)
)
class Box
<T> {
private
T t ; // T stands for "Type"
public void add (
T t){this.t=t}
public
T get() { return t} }
}
沒有留言:
張貼留言