Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Implementing "package" interfaces

Reply
Thread Tools

Implementing "package" interfaces

 
 
James D Carroll
Guest
Posts: n/a
 
      06-28-2004
Could someone explain this:

interface myInterface{
void foo();
}


then...

class myClass implements myInterface{
void foo(){
'do this
}
}


I want the Interface, its methods, and the implementing class and its
methods to have "package" level permissions. But I get the complier error:

attempting to assign weaker access privileges; was public

Could someone explain this (or provide a link that does) ?


Thanks



---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.711 / Virus Database: 467 - Release Date: 6/25/2004


 
Reply With Quote
 
 
 
 
Lance Lamboy
Guest
Posts: n/a
 
      06-28-2004
On Sun, 27 Jun 2004 23:21:55 -0400, James D Carroll wrote:

> Could someone explain this:
>
> interface myInterface{
> void foo();
> }
> }
>
> then...
>
> class myClass implements myInterface{
> void foo(){
> 'do this
> }
> }
> }
>
> I want the Interface, its methods, and the implementing class and its
> methods to have "package" level permissions. But I get the complier
> error:
>
> attempting to assign weaker access privileges; was public
>
> Could someone explain this (or provide a link that does) ?


Yes. Interface methods must be public and abstract. Since java knows
that all interface methods must be public and abstract, it lets you leave
out the keywords (in an interface).

A definitive source is the Java Language Specifications (google it).


>
> Thanks
>
>
>
> ---
> Outgoing mail is certified Virus Free. Checked by AVG anti-virus system
> (http://www.grisoft.com). Version: 6.0.711 / Virus Database: 467 -
> Release Date: 6/25/2004


--
Lance Lamboy

"I tell them the truth and they think it's hell." ~ Harry S. Truman

 
Reply With Quote
 
 
 
 
xarax
Guest
Posts: n/a
 
      06-28-2004
"Lance Lamboy" <(E-Mail Removed)> wrote in message
news(E-Mail Removed). com...
> On Sun, 27 Jun 2004 23:21:55 -0400, James D Carroll wrote:
>
> > Could someone explain this:
> >
> > interface myInterface{
> > void foo();
> > }
> > }
> >
> > then...
> >
> > class myClass implements myInterface{
> > void foo(){
> > 'do this
> > }
> > }
> > }
> >
> > I want the Interface, its methods, and the implementing class and its
> > methods to have "package" level permissions. But I get the complier
> > error:
> >
> > attempting to assign weaker access privileges; was public
> >
> > Could someone explain this (or provide a link that does) ?

>
> Yes. Interface methods must be public and abstract. Since java knows
> that all interface methods must be public and abstract, it lets you leave
> out the keywords (in an interface).
>
> A definitive source is the Java Language Specifications (google it).

/snip/

This is yet another reason why it is a good idea to
be very explicit when declaring anything in an interface.
I always use "public abstract void foo();" so that any
reader, including a newbie, cannot get confused as to
the intent.


 
Reply With Quote
 
=?UTF-8?B?IkRhcmlvIChkcmlua2luZyBjb++sgGVlIGluIHRoZSBv76yDY2XigKYpIg==?=
Guest
Posts: n/a
 
      06-28-2004
xarax wrote:

> This is yet another reason why it is a good idea to
> be very explicit when declaring anything in an interface.
> I always use "public abstract void foo();" so that any
> reader, including a newbie, cannot get confused as to
> the intent.


Java Language Specification discourage your idea:

For compatibility with older versions of the Java platform,
it is permitted but discouraged, as a matter of style, to
redundantly specify the abstract modifier for methods declared
in interfaces.

It is permitted, but strongly discouraged as a matter of style,
to redundantly specify the public modifier for interface methods.

I follow Java Language Specification suggestions.

- Dario
 
Reply With Quote
 
Chris Smith
Guest
Posts: n/a
 
      06-28-2004
Dario wrote:
> Java Language Specification discourage your idea:
>
> For compatibility with older versions of the Java platform,
> it is permitted but discouraged, as a matter of style, to
> redundantly specify the abstract modifier for methods declared
> in interfaces.
>
> It is permitted, but strongly discouraged as a matter of style,
> to redundantly specify the public modifier for interface methods.


Yes, it does. A large number of people, though, have found that this
section of the JLS is perhaps worded a bit too strongly. Since it's not
normative, it's not binding. Personally, I make it a practice to
declare interface methods as public, though not abstract (the lack of a
method body is sufficient to convey that, it seems).

I noticed yesterday that as of the most recent beta of 3.0, Eclipse
defaults to declaring interface methods public and abstract in the
'Extract Interface' refactoring; a testament to the number of people who
find it useful to do so despite the JLS.

Of course, the choice doesn't really make a lot of difference; it's
related more to maintaining subconscious connection to code than the
actual conscious element of understanding it. Competent Java
programmers know that interface methods are public and abstract anyway,
but it just often create a "huh" sort of moment to see a method without
an access specifier there.

--
www.designacourse.com
The Easiest Way to Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Implementing redundancy on 2 FastEhernet Interfaces on 2800 Satnam.Bhamra@gmail.com Cisco 1 03-08-2007 02:26 AM
extending classes and implementing interfaces C++ style interec@interec.net C++ 13 02-02-2007 06:11 PM
Declaring and implementing exceptions inside interfaces? josh Java 6 12-19-2006 08:29 AM
Is there a way to declare a reference as being a type implementing multiple interfaces? Oliver Wong Java 16 06-28-2006 05:22 PM
Implementing Legacy Byte Packed Message Interfaces Chris Java 6 11-07-2004 09:54 AM



Advertisments