Which is the final overrider?

Rémi Forax forax at univ-mlv.fr
Thu Jan 13 11:26:10 PST 2011


I suppose the code should be:

*class E extends D<String> {

*The section 8.4.8.4 of the JLS is clear, it should compile and print 2.
But there is a bug in javac, the bridge generated in E use invokespecial 
to call
C.foo(String) instead of invokevirtual.

Also note that there is a bug in eclipse. It doesn't compile at all.

Rémi

On 01/13/2011 07:55 PM, Neal Gafter wrote:
> I thought you might like to see this "bug" someone called to my 
> attention recently.  I don't know if it is a spec issue or a compiler 
> issue.
>
> Cheers,
> Neal
>
> ===========================
>
> Hi Neal,
>
> I wonder if you might be interested in considering a possible Java bug?
>
> *package pck;*
>
> *
> abstract class C<T> {
>     public abstract Object foo(T x);
>     public Integer foo(String x){ return 1; }
>     public void bar(T x){
>         System.out.println(foo(x));
>     }
> }*
>
> *class D<T> extends C<T> {
>     public Object foo(T x) {
>         return 2;
>     }
> }*
>
> *class E extends C<String>{
>     public static void main(String args[])
>     {
>         new E().bar(null);
>     }
> }*
>
> This code compiles successfully and... what do you think it prints?
>
> But if I reorder foo methods in C<T>, then the behavior changes.
>
> Is it a bug? What is by-design behavior for this code?
>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.openjdk.java.net/pipermail/compiler-dev/attachments/20110113/213ae0d4/attachment.html 


More information about the compiler-dev mailing list