aspose file tools*
The moose likes Java in General and the fly likes Interface Declarations - default static? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Interface Declarations - default static?" Watch "Interface Declarations - default static?" New topic
Author

Interface Declarations - default static?

Rodger Donaphon
Greenhorn

Joined: Jan 23, 2009
Posts: 4
I was preparing for the SCJP and discovered something about interface declarations not in my Liang textbook (unless I missed it).

The following code compiles OK.



Originally, I had the interfaces declared static, but when I took that away it still compiles.

It looks like I don't need a concrete class to use an interface declared in an abstract class.

If you try the above with inside classes instead of inside interfaces, you have to declare the inside classes static.

Is it true that in Java, interface declarations are static? Or is there another explanation?

Thanks in advance for any comments. I want to make sure I know the rules.
Mike Simmons
Ranch Hand

Joined: Mar 05, 2008
Posts: 3007
    
    9
Member interfaces (interfaces declared within another class or interface) are implicitly static. Top-level interfaces are not (since the word doesn't really mean anything in that context.)
James Boswell
Bartender

Joined: Nov 09, 2011
Posts: 1012
    
    5

Is it true that in Java, interface declarations are static? No

See here for more info on nested types: http://docs.oracle.com/javase/tutorial/java/javaOO/nested.html
Winston Gutkowski
Bartender

Joined: Mar 17, 2011
Posts: 7643
    
  19

Rodger Donaphon wrote:Is it true that in Java, interface declarations are static? Or is there another explanation?

Don't think so. To be honest, I'd never thought about it, but it does actually make sense: After all, you can't instantiate an interface, so what would an "inner" interface do?.

Winston


Isn't it funny how there's always time and money enough to do it WRONG?
Articles by Winston can be found here
Mike Simmons
Ranch Hand

Joined: Mar 05, 2008
Posts: 3007
    
    9
James, that seems to be the same question I just answered. My original answer still applies.

From JLS7 8.5.1:
A member interface is implicitly static (ยง9.1.1). It is permitted for the declaration of a member interface to redundantly specify the static modifier.
James Boswell
Bartender

Joined: Nov 09, 2011
Posts: 1012
    
    5

Apologies Mike, I only saw your reply once I had submitted mine. I ain't gonna argue with the JLS
Mike Simmons
Ranch Hand

Joined: Mar 05, 2008
Posts: 3007
    
    9
Ah, I should have noticed the proximity in timestamps.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Interface Declarations - default static?