Generic arrays do not compile in playground, BROKEN! | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Generic arrays do not compile in playground, BROKEN!

@SuppressWarnings("unchecked") throws an error. The generic array is initialized the following way: T[] t = (T[]) new Object [SOME_CAPACITY]; This code should work, https://code.sololearn.com/c8mOlo7lq988/?ref=app

11th Jan 2018, 4:11 AM
Darrell Cleveland
Darrell Cleveland - avatar
2 Answers
+ 3
It should not work, you are using t both as a variable and a parameter.
15th Jan 2018, 12:08 AM
Jacob Pembleton
Jacob Pembleton - avatar
0
@Jacob Pembleton Thanks. Forgot to reference the class instance inside the add method.
15th Jan 2018, 3:37 AM
Darrell Cleveland
Darrell Cleveland - avatar