Community
Participate
Working Groups
As far as I understood Java generics, it looks like there is no other way to instantiate a generic array. T [] myarray = (T[])new Object[size]; Eclipse 3.1M6 reports an unnecessary cast warning here, while removing the cast prevent the code to compile. It would be nice to correct that warning issue. unnecessary cast warnings are pretty helpful when moving existing code to "generic" code.
With latest we report: ---------- 1. WARNING in C:\tests_sources\Toto.java (at line 3) T [] myarray = (T[]) new Object[10]; ^^^^^^^^^^^^^^^^^^^^ Type safety: The cast from Object[] to T[] is actually checking against the erased type Object[] ---------- In fact, javac is reporting an unchecked cast warning: Toto.java:3: warning: [unchecked] unchecked cast found : java.lang.Object[] required: T[] T [] myarray = (T[])new Object[10]; ^ 1 warning This looks consistent. Ok to close?
This is another symptom of bug 78591. *** This bug has been marked as a duplicate of 78591 ***
ok, you can close.