Path: csiph.com!x330-a1.tempe.blueboxinc.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!border3.nntp.dca.giganews.com!Xl.tags.giganews.com!border1.nntp.dca.giganews.com!nntp.giganews.com!local2.nntp.dca.giganews.com!nntp.posted.palinacquisition!news.posted.palinacquisition.POSTED!not-for-mail NNTP-Posting-Date: Fri, 08 Apr 2011 02:14:49 -0500 Date: Fri, 08 Apr 2011 00:14:48 -0700 From: Peter Duniho User-Agent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.5; en-US; rv:1.9.2.13) Gecko/20101207 Thunderbird/3.1.7 MIME-Version: 1.0 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> In-Reply-To: <5YSdnThYKPSwAgPQnZ2dnUVZ_gydnZ2d@earthlink.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Message-ID: Lines: 45 X-Usenet-Provider: http://www.giganews.com NNTP-Posting-Host: 50.46.118.188 X-Trace: sv3-tnLevl6cjfSLenRAknbyL1tgilzRYshmdqfSLBiok3mDwcy9IURcAlG+S8B19Dgb5fppzKHucmk6fZe!YwSr72W58vsRRqzOiZhu52NlCJyEM7UxZUWmLF6BMoSfvszq8EBy7tlnQBF49eSk0BIVVPkighKb!6PuxU5BOnvxgwIs8yaL0sRzTSPJRrCOk8Ri6qyt3p+Q= X-Complaints-To: abuse@iinet.com X-DMCA-Complaints-To: abuse@iinet.com X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly X-Postfilter: 1.3.40 X-Original-Bytes: 2822 Xref: x330-a1.tempe.blueboxinc.net comp.lang.java.programmer:2987 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