Default for Object's protected method vs Lambda(IllegalAccessError)

bitter_fox bitterfoxc at gmail.com
Wed Jul 25 20:08:42 PDT 2012


Hi,
In Revision:1438 of langtools, default for Object's public method was
banned.
But I think default for protected method should be banned either because it
will become the cause of IllegalAccessError when we make a instance by
lambda or others:

public class Main
{
    interface I
    {
        void f();

        /**/public/**/ Object clone() default {return null;}
    }

    public static void main(String[] args)
    {
        I i = () -> {}; // preferred Object#clone(protected) implicitly
        i.clone(); // but I can refer to I#clone
    }
}

This program makes IllegalAccessError:
Exception in thread "main" java.lang.IllegalAccessError:
Main$1.clone()Ljava/lan
g/Object;
        at Main.main(Main.java:14)

Regards,
bitter_fox


More information about the lambda-dev mailing list