Re: Re: Visibility

Daniel Bonniot <[email protected]> Sun, 27 Mar 2005 16:32:41 +0200
Newsgroups gmane.comp.lang.nice.general
Message-ID <[email protected]>
ArtemGr wrote:
>>>  > It could seem to be sufficient to require that non-public methods
>>>  > have a default implementation (since they are not public,
>>>  > ambiguities cannot be created in other packages). But actually, you
>>>  > can create an ambiguity by declaring a new class that implements
>>>  > two interfaces.
>>>
>>> Sorry, lost me there.  What aspect of (multiple-inheritance based?)
>>> ambiguity here affects the visibility?
>>
>>
>>
>> Here is the potential problem:
>>
>> package p1;
>> interface I {}
>> interface I1 extends I {}
>> interface I2 extends I {}
>>
>> private String foo(I);
>> foo(I1 i1) = ...;
>> foo(I2 i2) = ...;
>>
>> package p2; import p1;
>> class A implements I1,I2 {}
>>
>> // ambiguity about foo(new A())
>>
>> If foo was public, you could solve the ambiguity in p2. With the 
>> restriction of no dispatch on interfaces for non-public methods, this 
>> case is ruled out.
> 
> 
> To me it is seems natural for module-visible methods (private ones) to 
> be completely invisible outside of the module. That is, when trying to 
> invoke foo(A) in the above example, the absence of method "foo" is 
> reported, instead of ambiguity. Package p2 is allowed to implement it's 
> own versions of foo(I1), foo(I2) and foo(A), private method foo defined 
> in another module just doesn't interfere with this in any way.

I think there is a misunderstanding. I did not specify how foo(A) can called 
from p2. Indeed it cannot be called directly because foo is private. However, 
it's still possible to reach it by calling a public method in p1 that call the 
helper method foo. Full example:

package p1;
interface I {}
interface I1 extends I {}
interface I2 extends I {}

private String foo(I);
foo(I1 i1) = ...;
foo(I2 i2) = ...;

public void bar(I i) = println(foo(i));

package p2; import p1;
class A implements I1,I2 {}

public void main(String args)
{
   bar(new A());
}


We need the restriction of dispatch on interfaces for non-public methods to 
prevent this problem.

Daniel


-------------------------------------------------------
SF email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users.
Discover which products truly live up to the hype. Start reading now.
http://ads.osdn.com/?ad_id=6595&alloc_id=14396&op=click