Bug 82288 - Wrong "Unnecessary cast" warning with generic array instantiation
Summary: Wrong "Unnecessary cast" warning with generic array instantiation
Status: RESOLVED DUPLICATE of bug 78591
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.1   Edit
Hardware: PC Linux
: P3 normal (vote)
Target Milestone: 3.1 M5   Edit
Assignee: JDT-Core-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-01-05 17:13 EST by Daniel Le Berre CLA
Modified: 2005-01-06 01:41 EST (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Daniel Le Berre CLA 2005-01-05 17:13:29 EST
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.
Comment 1 Olivier Thomann CLA 2005-01-05 17:22:50 EST
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?
Comment 2 Philipe Mulet CLA 2005-01-05 18:56:41 EST
This is another symptom of bug 78591.

*** This bug has been marked as a duplicate of 78591 ***
Comment 3 Daniel Le Berre CLA 2005-01-06 01:41:10 EST
ok, you can close.