Summary: | [1.5][compiler] Inferred type less restrictive than declared does not give error | ||
---|---|---|---|
Product: | [Eclipse Project] JDT | Reporter: | Philip Smith <diastrophism2> |
Component: | Core | Assignee: | Philipe Mulet <philippe_mulet> |
Status: | RESOLVED INVALID | QA Contact: | |
Severity: | normal | ||
Priority: | P3 | ||
Version: | 3.2 | ||
Target Milestone: | 3.3 RC1 | ||
Hardware: | PC | ||
OS: | Windows XP | ||
Whiteboard: |
Description
Philip Smith
2006-08-17 13:54:25 EDT
This is a bug in Javac, it fails to infer that under-constrained T should be 'Container'. Note that in a little variable, it does fine. import java.awt.Container; import java.util.Collection; public class X { private <T extends Container> Collection<T> foo() { return null; } private void showProblem() { Collection<?> result = (Collection<Container>) foo(); } } Previous comment should have said: "... Note that with a small variation, it does fine." Note: the variation with extra cast is not strictly equivalent, as with the cast it does NOT consider the expected type (Collection<?>) into the inference stage (pass2). Technically though, the expected type doesn't bring any useful information for inference, and should just end up with the same final result, i.e. T is underconstrained and should default to be Container. Inference from expected type with unbound wildcard (Collection<?>) is described in JLS 15.12.7, p.459. Added GenericTypeTest#test1137. Marking as invalid. |