Context inside default method body

Deepak S Patwardhan deepak.patwardhan at itaas.com
Thu Jul 19 22:43:05 PDT 2012


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