java容器--------泛型

package cn.zxg.collection; /** * 测试泛型 */ public class TestGenric { public static void main(String[] args) { MyCollection mc=new MyCollection<>(); mc.set("小白",1); mc.set("小黑",2); String b=mc.get(1); System.out.println(b); } } class MyCollection{ Object[] obj=new Object[5]; public void set(E e,int index){ obj[index]=e; } public E get(int index){ return (E)obj[index]; } }
posted on 2019-05-23 22:15  zz测试笔记  阅读(148)  评论(0编辑  收藏  举报