Public defender methods and static inner classes in interfaces?

Alex Buckley alex.buckley at oracle.com
Wed Sep 1 11:26:32 PDT 2010


No, the JVM checks class/interface accessibility before member 
accessibility. We know there is some work to do regarding the rules for 
default methods, don't worry.

Alex

On 8/31/2010 11:16 PM, Peter Levart wrote:
> On 09/01/10, Reinier Zwitserloot wrote:
>> Nice solution. That still depends on the question: Does the default method
>> have to be visible and/or accessible from the caller? If yes, then a
>> package-private class won't work.
> 
> I think that (havent checked the spec, but from my experience) the JVM does allow calling public method in an otherwise unaccessible class. It's just javac that does not allow compiling such program.
> 
> Regards, Peter
> 
>>  --Reinier Zwitserloot
>>
>>
>>
>> On Wed, Sep 1, 2010 at 4:45 AM, Andrew Thompson
>> <lordpixel+lamda-dev at mac.com<lordpixel%2Blamda-dev at mac.com>
>>> wrote:
>>> 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