Public defender methods and static inner classes in interfaces?

Andrew Thompson lordpixel+lamda-dev at mac.com
Tue Aug 31 19:45:59 PDT 2010


On Aug 24, 2010, at 6:25 AM, Reinier Zwitserloot wrote:

> The conclusion of some was that this pattern will be rather common, whether
> encouraged or not, and this has in fact been used as an argument to allow
> specifying the default implementation directly on an interface method,
> because this pattern has an ugly wart in it: The inner class must
> necessarily be public, and is thus visible (because all members of an
> interface are forced public). Making implementation details visible is bad
> API design.


Will the following compile in the prototype, assuming the whole thing is placed in Example.java?

public interface Example {
  public extension void method(Object parameter) default Trait.method;
}

class Trait {
  public void method(Example outer, Object parameter) {

  }
}

People often forget Java allows multiple non-public types in a compilation unit (File).

So this at least pushes the implementation to be package private.

Personally I think the body should be allowed inline with the above as the de-sugaring.


AndyT (lordpixel - the cat who walks through walls)
A little bigger on the inside

	(see you later space cowboy, you can't take the sky from me)




More information about the lambda-dev mailing list