Unchecked conversion and super raw type

Zhong Yu zhong.j.yu at gmail.com
Thu Apr 11 15:40:26 PDT 2013


On Thu, Apr 11, 2013 at 5:10 PM, Zhong Yu <zhong.j.yu at gmail.com> wrote:

> Consider this example:
>
> public class Test
> {
>     static class A<T> {}
>
>     static class B extends A {}
>
>     void foo(A<String> a) {}
>
>     void foo(B b) {}
>
>     void test()
>     {
>         B b = new B();
>         foo(b); // error: reference to foo is ambiguous
>     }
> }
>
> For the method invocation expression `foo(b)`, method `foo(B)` is
> applicable by subtyping. However is that also true for `foo(A<String>)`? By
> the letter of the spec, we cannot find a Ci such that "B" is convertible to
> Ci by unchecked conversion and Ci <: A<String>. So my understanding is that
> `foo(A<String>)` is not applicable to `foo(b)` by subtyping, and the code
> should compile since only one applicable method is found during "15.12.2.2.
> Phase 1"
>
>
>
Or, is this a bug of the spec? Maybe the spec intends to say

For 1 ≤ *i* ≤ *n*, either:

   -

   Ai <: Si (§4.10<http://docs.oracle.com/javase/specs/jls/se7/html/jls-4.html#jls-4.10>),
   or
   -

   Ai <: |Si|

The second clause is for the legacy code that saw a non-generic method
parameter type.

Zhong Yu
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.openjdk.java.net/pipermail/compiler-dev/attachments/20130411/e765bb5b/attachment.html 


More information about the compiler-dev mailing list