Java 删除警告(类型安全:从捕获未选中强制转换#2-of?将模板扩展到T)
在我的IF中,所有3行都有警告。没有Suppress我怎么能移除它?有更好的解决办法吗Java 删除警告(类型安全:从捕获未选中强制转换#2-of?将模板扩展到T),java,reflection,Java,Reflection,在我的IF中,所有3行都有警告。没有Suppress我怎么能移除它?有更好的解决办法吗 public void template() throws NoSuchMethodException, SecurityException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException{ if(templateResult == null
public void template() throws NoSuchMethodException, SecurityException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException{
if(templateResult == null){
Class templateClass = getGenericTypeArgument(this.getClass(), 0);
Constructor<? extends Template> constructor = templateClass.getConstructor(new Class[]{List.class, List.class});
templateResult = (T) constructor.newInstance(listData, listaDataRes);
}
}
public void template()抛出NoSuchMethodException、SecurityException、InstanceionException、IllegalAccessException、IllegalArgumentException、InvocationTargetException{
if(templateResult==null){
类templateClass=getGenericTypeArgument(this.getClass(),0);
构造函数您可以通过不使用以下命令来删除其中一些命令:
Class templateClass=getGenericTypeArgument(this.getClass(),0);
// ^
构造函数您可以为此类提供代码吗?通常您不应该看到任何警告。如果您这样做,则意味着您的代码中有一些非标准的内容此测试是在一个孤立的类中。我有3个警告:class templateClass=getGenericTypeArgument(this.getClass(),0);此行有多个标记-类是原始类型。对泛型类型类的引用应参数化-类是原始类型。对泛型类型类的引用应参数化
Class<?> templateClass = getGenericTypeArgument(this.getClass(), 0);
// ^
Constructor<? extends Template> constructor =
templateClass.getConstructor(new Class<?>[]{List.class, List.class});
// ^