I have the following code, but it won’t compile:
Class<? extends something>[] classes = new Class<? extends something>[5]();
Why exactly won’t this work? And is there a way around this? I also tried it with Class<?> and that didn’t work either.
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.
The answer has to do with Array Creation Expression.
The rule clearly states:
That’s why your above code will never compile. In fact, the following compile-time error message shows (example):
Solution (that works, if you follow the above rule):
The above line compiles.
I hope this helps.