Re: Visibility
ArtemGr <[email protected]> Sun, 27 Mar 2005 19:19:33 +0400
| Newsgroups | gmane.comp.lang.nice.general |
|---|---|
| Message-ID | <[email protected]> |
> 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
I've missed the fact that private methods should be dispatched too (have
been accustomed to C++ and Java private methods which aren't dispatched).
Now I understand the "public-only dispatch on interfaces" restriction.
Still, would it be possible to write the following?
package p1;
class A {}
private void foo( A a ) = ...;
package p2;
class B extends A {}
private int foo( A a ) = ...;
private int foo( B b ) = ...;
That is, if the foo is module-private, then it should be possible to
define another foo in another module, which have nothing in common with
the first foo.
-------------------------------------------------------
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