When I cast to E[]
(the class parameter), it requires me to add
@SuppressWarnings("unchecked")
For example:
E[] anArray = (E[]) new Object[10];
Should I be doing something different, or is it supposed to be like this?
Thanks
It is correct. Imagine:
Object[] o = new Object[10];
o[0] = new A(); // A is not a subclass of E
E[] e = o; // Now you have broken the type system: e[0] references something that is not an E.
The way it works, you have to explicitly cast in order to make the compiler ignore this possibility.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With