加载中...

泛型

/**
测试泛型
*/
public class TestGeneric {
public static void main(String[] args) {

MyCollection mc = new MyCollection();

mc.set("老王", 0);

String b = mc.get(0);

System.out.println(b);
}
}

class MyCollection { //容器
Object[] objs = new Object[5];

public void set(E e, int index) {
objs[index] = e;
}

public E get(int index) {
return (E)objs[index];
}
}

posted @ 2021-08-14 11:03  nongeason  阅读(54)  评论(0)    收藏  举报