Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/399.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 删除警告(类型安全:从捕获未选中强制转换#2-of?将模板扩展到T)_Java_Reflection - Fatal编程技术网

Java 删除警告(类型安全:从捕获未选中强制转换#2-of?将模板扩展到T)

Java 删除警告(类型安全:从捕获未选中强制转换#2-of?将模板扩展到T),java,reflection,Java,Reflection,在我的IF中,所有3行都有警告。没有Suppress我怎么能移除它?有更好的解决办法吗 public void template() throws NoSuchMethodException, SecurityException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException{ if(templateResult == null

在我的IF中,所有3行都有警告。没有Suppress我怎么能移除它?有更好的解决办法吗

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});
//                                         ^