泛型类:
public class FanXingLeiDemo
private T obj;
public T getObj() {
return obj;
}
public void setObj(T obj) {
this.obj = obj;
}
}
实现:
public class FanXingMain {
public static void main(String[] args) {
FanXingLeiDemo
fxd.setObj("hahaha");
System.out.println(fxd.getObj());
}
}
泛型方法:
public class FanXingMethod {
public
{
System.out.println(t);
}
}
实现:
public class FangXingMethodMain {
public static void main(String[] args) {
FanXingMethod fxm = new FanXingMethod();
fxm.show(100);
fxm.show("shshh");
fxm.show(true);
}
}
泛型接口:
public interface Inter
public abstract void show(T t);
}
实现接口:
public class InterImpl
@Override
public void show(T t) {
// TODO 自动生成的方法存根
System.out.println(t);
}
}
实例化:
public class InterMain {
public static void main(String[] args) {
Inter
in.show("hahah");
}
}
更多关于java中的 泛型类、泛型方法、泛型接口相关文章请关注PHP中文网!