package collection;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
- 测试泛型
- @author ly
*/
public class TestGeneric {
public static void main(String[] args) {
MyCollection<String> mc = new MyCollection<>();//MyCollection<String>(); 后面可以空着
mc.set("aaaa", 0);
// mc.set(8888, 1);
String b = mc.get(0);
// Integer a = (Integer)mc.get(1);
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];
}
}