tags:

views:

89

answers:

2

Why can I not create a map with the following generics?

Map<Class<K extends Item>, K> classMap;
+6  A: 

Because Map is already generified - your job when creating a reference is to fill in the type parameter. Unless this is inside a method parameterized with K, the compiler will have no idea what K should be replaced with (and if it were inside a parameterized method, you couldn't have K extends Item in the body - K either already extends Item, or it doesn't).

New type parameters can go in the signatures of classes and methods with the implicit promise that they will be filled in later. They cannot go inside declarations.

danben
Dang, I was worried it was something along those lines.
Sionide21
+1  A: 

Here you are making an instance of Map, not defining it. K needs to be a specific class.

fastcodejava