我看到了类似的问题,但它们并没有太大帮助。
例如,我有这个通用类:
public class ContainerTest<T>
{
public void doSomething()
{
//I want here to determinate the Class of the type argument (In this case String)
}
}
另一个使用这个容器类的类
public class TestCase
{
private ContainerTest<String> containerTest;
public void someMethod()
{
containerTest.doSomething();
}
}
在没有显式类型变量/字段或任何构造函数的情况下,是否可以确定方法doSomething()中类型参数的类别?
更新:更改了ContainerTest类的格式。