+ 25

Java Generics - Array Restrictions

I cannot instantiate an array whose base type is a type parameter. why? Here, I've written the problem: https://code.sololearn.com/cdMeKYymB6L4

11th Jun 2018, 1:17 PM
Amir
Amir - avatar
5 Answers
+ 18
Arun Tomar : I changed the code as you said but again there is a exception.
14th Jun 2018, 12:41 PM
Amir
Amir - avatar
+ 6
Amir you did a very small mistakes bro.. MyClass<?> myClasses[] = new MyClass<?>[20]; this is work fine becoause of the parametrised constructor in MyClass but In class Gen by default there is default constructor and you try to access the parameterised constructor that you not created ... i hope you understand now try to used javap decompiler of java you understand alot
12th Jun 2018, 6:58 PM
Arun Tomar
Arun Tomar - avatar
+ 4
Amir yes you change.. but the way you cheated the array of generics type is wrong mam.. i comments also. i hope you go through it
14th Jun 2018, 1:15 PM
Arun Tomar
Arun Tomar - avatar
+ 2
It's a well-known platform where you can earn or hire https://www.freelancer.com/get/davarak
24th Jun 2018, 11:34 AM
Davit Arakelyan
Davit Arakelyan - avatar
- 1
java is itself a creation of classes in terms of constructor as same as class before you can use it .it should be declared and initialized first .i hope you understand my point
13th Jun 2018, 11:25 AM
Imtiyaz Bhat