简体   繁体   English

类型不匹配:无法从Class转换 <capture#1-of ?> 上课 <?> []

[英]Type mismatch: cannot convert from Class<capture#1-of ?> to Class<?>[]

What does it mean, the following error message: 这是什么意思,以下错误消息:

Type mismatch: cannot convert from Class<capture#1-of ?> to Class<?>[]

The code is following: 代码如下:

            Class<?>[] encoderClass;
            Class<?>[] encoderClasses = new Class<?>[] {
                Encoder1.class,
                Encoder2.class,
                Encoder3.class
            };

            for(int i=0; i<encoderClasses.length; ++i) {
                encoderClass = encoderClasses[i]; // <------ error is here
            }

UPDATE UPDATE

Oh, just silly mistake, thanks.... 哦,只是愚蠢的错误,谢谢....

You're attempting to assign a single class element to a class array (different types as per the error message). 您正在尝试将单个类元素分配给类数组(根据错误消息的不同类型)。 Instead assign each individual element in the for loop 而是在for循环中分配每个单独的元素

encoderClass[i] = encoderClasses[i];

ensuring that the array is initialized to avoid NPE in the assignment 确保初始化数组以避免赋值中的NPE

Class<?>[] encoderClass = new Class<?>[3];

For simplicity you could replace the entire loop with 为简单起见,您可以用。替换整个循环

encoderClass = Arrays.copyOf(encoderClasses,  encoderClasses.length);

You are expecting array from Class. 你期待Class的数组。

You should change the following from: 您应该更改以下内容:

Class<?>[] encoderClass;

To: 至:

Class<?> encoderClass;

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 类型不匹配:无法从类&lt;..&gt;转换为类&lt;…&gt; - Type mismatch: cannot convert from Class <..> to Class <…> 类型不匹配:无法从类转换 <Parameterized> 上课 <? extends Runner> - Type mismatch: cannot convert from Class<Parameterized> to Class<? extends Runner> Java泛型编译错误“类 - Java generics compile error “Class<capture#1-of ? …” 类型不匹配:无法从Object转换为Class对象 - Type mismatch: cannot convert from Object to Class object 类型不匹配:无法从 String 转换为 Class<!--?--> Java(16777233) - Type mismatch: cannot convert from String to Class<?>Java(16777233) Java泛型编译错误-方法method(Class <capture#1-of ? extends Interface> ) <type> 不适用于参数 - Java generics compilation error - The method method(Class<capture#1-of ? extends Interface>) in the type <type> is not applicable for the arguments 泛型:无法从 <capture#1-of ? extends Object,D> 至 <S,D> - Generics: cannot convert from <capture#1-of ? extends Object,D> to <S,D> Play 2.5 ActorFlow:无法从 Flow 转换<string,string,capture#1-of ?>流动<string,string,?></string,string,?></string,string,capture#1-of> - Play 2.5 ActorFlow: cannot convert from Flow<String,String,capture#1-of ?> to Flow<String,String,?> 类型不匹配:无法从捕获#2转换?将Number扩展为T. - Type mismatch: cannot convert from capture#2-of ? extends Number to T 类型不匹配:无法从 Class 转换<rulesgenerator>至 Class<!--? extends IGenerator2--> x测试错误</rulesgenerator> - Type mismatch: cannot convert from Class<RulesGenerator> to Class<? extends IGenerator2> xtest error
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM