自定义一个类使用泛型

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());
}
}

原文地址:https://www.cnblogs.com/Koma-vv/p/9561636.html