Which is the final overrider?

Jonathan Gibbons jonathan.gibbons at oracle.com
Thu Jan 13 10:58:37 PST 2011


Neal,

Thanks for forwarding this.

-- Jon

On 01/13/2011 10:55 AM, 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/b23d9236/attachment.html 


More information about the compiler-dev mailing list