Problem about generics and class array

K

Kaiser S.

Can somebody explains why the last line of code doesn't compile ?

public class TestClassArray {
private static class A {
}
private static class B extends A {
}

Class[] rawClasses = { B.class }; // warning

Class<?>[] wildcardsClasses = { B.class };

// error : Cannot create a generic array of Class<? extends
TestClassArray.A>
Class<? extends A>[] upperBoundClasses = { B.class };
}
 
I

Ingo R. Homann

Hi usual suspect, ;-)
Can somebody explains why the last line of code doesn't compile ?

Class<? extends A>[] upperBoundClasses = { B.class };

Because Generic Arrays are not allowed. (Read the fine error message ;-)

Ciao,
Ingo
 
I

Ingo R. Homann

Hi, Mr. Spacey ;-)
Can somebody explains why the last line of code doesn't compile ?

Class<? extends A>[] upperBoundClasses = { B.class };

Because Generic Arrays are not allowed. (Read the fine error message ;-)

Damned! Thx for your help :)

Note that a

List<Class<? extends A>>

is perfectly OK!

Ciao,
Ingo
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

generics puzzle 57
Generics ? 14
Problem with generics and dynamic array copy 7
Hairy generics question 29
Generics and Polymorphism 5
Generics 12
question about casting and inheritance 8
Delegation and generics craziness 9

Members online

Forum statistics

Threads
473,776
Messages
2,569,603
Members
45,188
Latest member
Crypto TaxSoftware

Latest Threads

Top