泛型分为类泛型,方法泛型,接口泛型
类泛型:public class Lei<T> {};
方法泛型 public<T> void ***(){};
接口泛型 Interface ***<T> {};
泛型的使用:类的实现
public class ShiXian01 implements interfance01<String> {
@Override
public String getT(String t) {
// TODO Auto-generated method stub
System.out.println(t);
return null;
}
public String getT(String t) {
// TODO Auto-generated method stub
System.out.println(t);
return null;
}
}
public class ShiXian02<T> implements interfance01<T>{
@Override
public T getT(T t) {
// TODO Auto-generated method stub
System.out.println(t);
return null;
}
public T getT(T t) {
// TODO Auto-generated method stub
System.out.println(t);
return null;
}
}
public class Text {
public static void main(String[] args) {
// TODO Auto-generated method stub
MyFanXing<String> my1=new MyFanXing<String>();
my1.t="12121";
my1.show("yyy");
ShiXian01 s1=new ShiXian01();
s1.getT("eee");
ShiXian02 s2=new ShiXian02();
s2.getT(18);
}
// TODO Auto-generated method stub
MyFanXing<String> my1=new MyFanXing<String>();
my1.t="12121";
my1.show("yyy");
ShiXian01 s1=new ShiXian01();
s1.getT("eee");
ShiXian02 s2=new ShiXian02();
s2.getT(18);
}
}
***************************
public interface interfance01<T> {
T getT(T t);
}
T getT(T t);
}
实现接口必须重写这个方法,抽象类除外