package demo01;
/*
测试含有泛型的方法
*/
public class Demo05GenericMethod {
public static void main(String[] args) {
//创建GenericMethod对象
GenericMethod g=new GenericMethod();
/*
调用含有泛型的方法method01
传递什么类型,泛型就是什么类型
*/
g.method01(22);
g.method01("jj");
g.method01(0.90);
g.method01(false);
g.method02("静态方法,不建议创建对象使用");
//静态方法,通过类名.方法名(参数)可以直接使用
GenericMethod.method02("静态方法");
GenericMethod.method02("yy");
}
}
package demo01;
public class GenericMethod {
//定义一个含有泛型的方法
public <M> void method01(M m){
System.out.println(m);
}
//定义一个含有泛型的静态方法
public static <S> void method02(S s){
System.out.println(s);
}
}