Formal model for defender method resolution

Peter Levart peter.levart at gmail.com
Tue Feb 1 08:22:49 PST 2011


On Tuesday, February 01, 2011 02:13:45 pm Stephen Colebourne wrote:
> On 1 February 2011 13:05, Peter Levart <peter.levart at marand.si> wrote:
> > But this allows one to question whether also the following is possible
> > (and why not?)
> > 
> > interface A {
> >  Object m() default Defaults.m;
> > }
> > 
> > interface B extends A {
> >  Object n() default A.m;
> > }
> > 
> > .. which is confusing.
> 
> Why confusing? Its obvious to me:
> 
> A's author says  "please use Defaults.m if not overridden".
> B's author says  "please use A.m() if not overridden".
> 
> In general it says "if not overridden then use x". We shouldn't be
> stricter than we need to be about what "x" is.
> 
> I will grant that there is a new circular reference possibility
> introduced if two defaults in the same interface reference each other.
> 
> Stephen

I wouldn't go so far as to point to defaults in other types. Where to put restrictions to such 
pointers? 

Can we only point to methods in super-types? Of course.

What about pointing to a method in a type which is not an imediate supertype? Isn't that to 
fragile?

What about pointing to compatible methods that are not actualy overriden by the overriding 
method? Arent we creating a "pasta" of pointers that way?

If a bare "default" keyword is not descriptive enough, then maybe the following is more 
descriptive:

interface A {
  void m() default Defaults.m;
}

interface B {
  void m() default super;
}

.. which would mean: "the default implementation is the same as the overriden methods' default 
implementation from the supertype(s)" including the non-existence of such default 
implementation. 

So, for example, if vendor A defines interface VendorA without the default implementation for 
method m:

interface VendorA {
  void m();
}

and vendor B extends this interface with:

interface VendorB extends VendorA {
  ...
  void m() default super;
}

...this means that vendor B is giving vendor A the mandate to control the default of that method 
in the future. If in the future vondor A adds a default for that method, it will be inherited by 
B.


Peter


More information about the lambda-dev mailing list