package cn.itcast.demoDateformat; /* *定义含有泛型的方法:泛型定义在方法的修饰符和返回值之间 * 格式: * 修饰符 <泛型> 返回值类型 方法名(参数列表(使用泛型)){ * 方法体} * 含有泛型的方法,在调用方法的时候确定泛型的数据类型 * 传递什么类型的参数,泛型就是什么类型 * 定义一个含有静态的泛型方法 * */ public class demo12 { //定义一个含有泛型的方法 public <M> void genericmethod(M method){ System.out.println(method); } public static <M> void genericmethod2(M method){ System.out.println(method); } }
=================================================================================================
package cn.itcast.demoDateformat; public class demo13 { public static void main(String[] args) { demo12 method = new demo12(); method.genericmethod(1); method.genericmethod("hello world!"); demo12.genericmethod2(1314); } }