Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #2987

Re: Why only public methods on interfaces?

Date 2011-04-08 00:14 -0700
From Peter Duniho <NpOeStPeAdM@NnOwSlPiAnMk.com>
Newsgroups comp.lang.java.programmer
Subject Re: Why only public methods on interfaces?
References <25875c94-9af2-4d28-976d-2050a738ae2e@n10g2000yqf.googlegroups.com> <4sOdneh7k40lDgPQnZ2dnUVZ_vSdnZ2d@earthlink.com> <2011040801014026003-angrybaldguy@gmailcom> <5YSdnThYKPSwAgPQnZ2dnUVZ_gydnZ2d@earthlink.com>
Message-ID <KPCdnfEJDvZ0KAPQnZ2dnUVZ_sqdnZ2d@posted.palinacquisition> (permalink)

Show all headers | View raw


On 4/7/11 10:37 PM, Patricia Shanahan wrote:
> [...]
>> As Stefan pointed out, interfaces themselves don't have to be public.
>> This is legal:
>>
>> package com.example;
>>
>> interface SomeInternalAbstraction {
>> public void flog(Horse horse);
>> }
>>
>> -o
>>
>
> Yes, but then the implementing methods do have to be public, which is
> undesirable if they should not be used outside the package.

The implementing type doesn't have to be public either.

Perhaps a future version of Java will include a feature C# offers: 
explicit implementation of an interface.  In C#, one can implement an 
interface implicitly as in Java, in which case if the implementing type 
is visible, then yes…one has access to the public members of that type 
that implement the interface.

But one can also implement interfaces explicitly, necessarily implying 
that a member is private, used only to implement an interface:

   interface IA { void A(); }

   class A : IA { void IA.A(); }

In that case, one can only call IA.A through an interface reference, and 
not a reference typed as A:

   A a = new A();
   IA ia = a;

   ia.A(); // legal
   a.A(); // not legal

In the meantime, in Java if you don't want the implemented methods 
called, just keep the implementing type non-public as well.

Pete

Back to comp.lang.java.programmer | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

Why only public methods on interfaces? kramer31 <kramer.newsreader@gmail.com> - 2011-04-07 17:09 -0700
  Re: Why only public methods on interfaces? Arved Sandstrom <asandstrom3minus1@eastlink.ca> - 2011-04-07 21:48 -0300
  Re: Why only public methods on interfaces? Joshua Cranmer <Pidgeot18@verizon.invalid> - 2011-04-07 21:01 -0400
    Re: Why only public methods on interfaces? v_borchert@despammed.com (Volker Borchert) - 2011-04-08 02:43 +0000
      Re: Why only public methods on interfaces? Joshua Cranmer <Pidgeot18@verizon.invalid> - 2011-04-08 00:24 -0400
  Re: Why only public methods on interfaces? Patricia Shanahan <pats@acm.org> - 2011-04-07 21:49 -0700
    Re: Why only public methods on interfaces? Owen Jacobson <angrybaldguy@gmail.com> - 2011-04-08 01:01 -0400
      Re: Why only public methods on interfaces? Patricia Shanahan <pats@acm.org> - 2011-04-07 22:37 -0700
        Re: Why only public methods on interfaces? Peter Duniho <NpOeStPeAdM@NnOwSlPiAnMk.com> - 2011-04-08 00:14 -0700
          Re: Why only public methods on interfaces? Patricia Shanahan <pats@acm.org> - 2011-04-08 06:59 -0700
            Re: Why only public methods on interfaces? Peter Duniho <NpOeStPeAdM@NnOwSlPiAnMk.com> - 2011-04-08 07:17 -0700
              Re: Why only public methods on interfaces? Patricia Shanahan <pats@acm.org> - 2011-04-08 08:59 -0700
                Re: Why only public methods on interfaces? Peter Duniho <NpOeStPeAdM@NnOwSlPiAnMk.com> - 2011-04-08 17:27 -0700
                Re: Why only public methods on interfaces? "Mike Schilling" <mscottschilling@hotmail.com> - 2011-04-09 22:14 -0700
                Re: Why only public methods on interfaces? "Mike Schilling" <mscottschilling@hotmail.com> - 2011-04-09 22:28 -0700
                Re: Why only public methods on interfaces? Tom Anderson <twic@urchin.earth.li> - 2011-04-10 16:02 +0100
  Re: Why only public methods on interfaces? Roedy Green <see_website@mindprod.com.invalid> - 2011-04-08 03:18 -0700
    Re: Why only public methods on interfaces? Esmond Pitt <esmond.pitt@bigpond.com> - 2011-04-08 20:32 +1000
  Re: Why only public methods on interfaces? Tom Anderson <twic@urchin.earth.li> - 2011-04-08 20:34 +0100
  Re: Why only public methods on interfaces? Tom Anderson <twic@urchin.earth.li> - 2011-04-10 18:10 +0100

csiph-web