Context inside default method body
Maurizio Cimadamore
maurizio.cimadamore at oracle.com
Fri Jul 20 02:00:18 PDT 2012
Nice catch - the accessibility rules for 'protected' in the compiler are
oblivious to extension methods. I don't see any change in the spec draft
regarding this - but it feels like something that should be
special-cased for the sake of consistency.
Maurizio
On 20/07/12 06:43, Deepak S Patwardhan wrote:
> Hi all,
>
> The following doesn't compile with the latest build of lambda :
>
> public interface Islander {
>
> public void replaceLiver() default {
> try {
> Object myClone = this.clone(); //.. Compile error
> //.. get the replacement from myClone
> } catch (CloneNotSupportedException cnse) {
> throw new UnsupportedOperationException();
> }
> }
> }
>
> Basically, I cannot access clone(), which is protected in Object, in spite
> of having the *this* reference.
>
> I think that's ok and not a big deal since Object has only two protected
> methods, and the other method (finalize) shouldn't be invoked by anyone,
> except the GC. But, it just feels like a minor anomaly that default bodies
> can do everything that normal (ie Class) methods can do, except that they
> cannot clone their callees. (Don't hold limitations of Interfaces against
> them, like access to instance variables)
>
> Regards,
> Deepak S Patwardhan.
>
>
More information about the lambda-dev
mailing list