用法
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.List;
public class StaticMethod {
public static void main(String[] args) {
System.out.println(test("aaaaa")); //aaaaa 基本用法
System.out.println(test1("aa").get(0).equals("aa")); //true 用于内部包装
System.out.println(test2(new HashSet(), Collection.class).size()); //0 用于强制转换类型
System.out.println(test3("bbbbb")); //bbbbb 装神弄鬼
}
public static<T> T test(T obj){
return obj;
}
public static<T> List<T> test1(T obj){
List<T> list = new ArrayList();
list.add(obj);
return list;
}
public static<T> T test2(Object str, Class<T> obj){
return (T)str;
}
public static<T, A, B, C, D> B test3(B obj){
return obj;
}
}
原文地址:https://blog.csdn.net/m18870420619/article/details/79929316