62,616
社区成员
发帖
与我相关
我的任务
分享
public class MyList<T>{
public static void main(String[] args){
}
}
class User(){
}
class MyList<T>{
}
public class Test{
public static void main(String)[
MyList<User> us = new MyList(User);
// 如何通过us获取 T 的类型?
}
}
public String loophole(Integer x) {
List<String> ys = new LinkedList<String>();
List xs = ys;
xs.add(x); // compile-time unchecked warning
return ys.iterator().next();
}
通过类型擦除转化为:
public String loophole(Integer x) {
List ys = new LinkedList;
List xs = ys;
xs.add(x);
return (String) ys.iterator().next(); // run time error
}