【发布时间】:2012-09-09 18:36:36
【问题描述】:
以下代码在类型擦除后在运行时看起来是什么:
public class Test<T> {
T lst;
List<T> list1;
void meth() throws InstantiationException, IllegalAccessException{ T res = (T)lst.getClass().newInstance();}
static <S> void meth(S t){}
}
class TestUse{
public static void main(String[] args) {
Test<Integer> gint = new Test<Integer>();
Test<String> gstr = new Test<String>();
gint.meth();
gstr.meth();
}
【问题讨论】:
-
你还没有定义
Genrics类。 -
类型擦除后
Genrics<Integer> gint = new Genrics<Integer>();看起来像Genrics gint = new Genrics();。 -
它在运行时“看起来不像”任何东西,因为它不能编译。
标签: java generics type-erasure