自定义一个类使用泛型

package com.bjpowernode.t02generic;

/*
* 泛型模板
* 自定义一个类使用泛型
*/
public class MyList<E> {

E e;

public E getE() {
System.out.println(e.getClass());
return e;
}

public void setE(E e) {
this.e = e;
}

//如果在静态方法中使用类名上定义的泛型,编译会报错
//需要在静态方法上重新定义
public static<S> void m1(S s) {
System.out.println(s.getClass());
}
}

posted @ 2018-08-30 17:44  Monica_维维  阅读(387)  评论(0编辑  收藏  举报