package day2;
import java.util.Collection;
public class GenericMethod<E> {
//范型方法上,参数范型可以传入任意类型,但是返回参数类型
public static void main(String[] args) {
// TODO Auto-generated method stub
GenericMethod g=new GenericMethod();
String str=g.method(1, 2);//错,“<T> T method(T t1,T t2)”-普通方法的返回T,需要强转,或者为Object类
String str1=methodStatic(2,3.2); //错
Number num=methodStatic(2.3,3);//对,"static <T> T methodStatic(T t1,T t2)"-静态方法,Nmuber是两个参数的父类
Object n=g.methodW(2,3.3);//对
}
public E methodW(E e1,E e2)
{
return null;
}
public static <T> T methodStatic(T t1,T t2)
{
return null;
}
public <T> T method(T t1,T t2)
{
return null;
}
public <T> T method (Collection<String> c,T t)
{
return null;
}
}