天天看點

泛型

測試泛型

/**

*/

public class TestGeneric {

public static void main(String[] args) {

MyCollection<String> mc = new MyCollection<String>();

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

      String b = mc.get(0);

      System.out.println(b);
        }
}

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

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

  public E get(int index) {
      return (E)objs[index];
  }
}      
上一篇: 如何訓練GAN
下一篇: 委托和事件

繼續閱讀