Which is the final overrider?

Neal Gafter neal at gafter.com
Thu Jan 13 10:55:07 PST 2011


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/a3256457/attachment.html 


More information about the compiler-dev mailing list