/*
* 泛型方法:类型推导
*/
/*
* 在方法中参数没有类型参数时,此时的推导根据 赋值
* String s = test("acb") //此时的类型根据前面的String 面返回 String
* 但对于convert,string s = convert("abc") 其类型参数根据 参数来推断的,传进
* 去什么参数,类型参数就是什么
*/
public static<T> T covert(T o) {
System.out.println(o.getClass());
return (T)o;
}
public static <T> T test(Object a) {
return (T) a;
}
public static void showString(String str) {
System.out.println(str);
}
public static void showObject(Object str) {
System.out.println(str);
}
泛型方法-类型推导
最新推荐文章于 2022-07-18 19:37:12 发布