| Summary: | Wrong Warning (type safety) when casting to reifiable type | ||
|---|---|---|---|
| Product: | [Eclipse Project] JDT | Reporter: | Dirk Willecke <public> |
| Component: | Core | Assignee: | JDT-Core-Inbox <jdt-core-inbox> |
| Status: | CLOSED WORKSFORME | QA Contact: | |
| Severity: | normal | ||
| Priority: | P3 | CC: | hashproduct+eclipse |
| Version: | 3.2 | ||
| Target Milestone: | --- | ||
| Hardware: | PC | ||
| OS: | Windows XP | ||
| Whiteboard: | |||
I ran into the same problem and found the same workaround. The message "cast to T is actually checking against T" makes no sense; I agree that it should be removed. I'm using Fedora Core's Eclipse 3.1.1 with "Build id: M20050929-0840". Another workaround is to cast the object to a raw type first. The extra cast generates an "unnecessary cast" warning, but that's better than an unchecked warning. TestList b1 = (TestList) (ArrayList) a1; Added regression test org.eclipse.jdt.core.tests.compiler.regression.GenericTypeTest#1052. Could not reproduce in HEAD. I confirmed that the problem seems to be gone in HEAD. Closing. Thanks for double-checking. |
public class TestList extends java.util.ArrayList<Integer> { static void test() { java.util.ArrayList<?> a1 = new TestList(); TestList b1 = (TestList) a1; // Warning: The cast from ArrayList<capture-of ?> to TestList // is actually checking against the erased type TestList TestList c1 = TestList.class.cast(a1); // Workaround without warning java.util.ArrayList<Integer> a2 = new TestList(); TestList b2 = (TestList) a2; // No warning for cast from ArrayList<Integer> } } Tested against: 3.2M3 stable build and I20051108-1011 TestList is reifiable. Imho there shouldn't be a warning.