Why can I not create a map with the following generics?
Map<Class<K extends Item>, K> classMap;
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Because
Mapis already generified – your job when creating a reference is to fill in the type parameter. Unless this is inside a method parameterized withK, the compiler will have no idea whatKshould be replaced with (and if it were inside a parameterized method, you couldn’t haveK extends Itemin the body –Keither already extendsItem, 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.