Home > DeveloperSection > Forums > cannot convert from Class<capture#1-of ?> to Class<?>[]
marcel ethan
marcel ethan

Total Post:105

Posted on    November-04-2014 11:53 PM

 Java Reflection  Syntax Error 

 1 Reply(s)
 732  View(s)
Rate this:

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<?>[] {

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

Pawan Shukla
Pawan Shukla

Total Post:29

Posted on    November-05-2014 3:08 AM

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

encoderClass[i] = encoderClasses[i];

ensuring that the array is initialized to avoid NPE in the assignment

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

For simplicity you could replace the entire loop with

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

Don't want to miss updates? Please click the below button!

Follow MindStick