aspose file tools*
The moose likes Beginning Java and the fly likes Static Interfaces Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Static Interfaces" Watch "Static Interfaces" New topic
Author

Static Interfaces

Arun Kumarr
Ranch Hand

Joined: May 16, 2005
Posts: 513

Why is that the enclosing interface cannot be marked static whereas the enclosed interface can be marked static?

Any comments!!!


If you are not laughing at yourself, then you just didn't get the joke.
Barry Gaunt
Ranch Hand

Joined: Aug 03, 2002
Posts: 7729


Enclosing interfaces can be static.
Do you mean a top-level interface? If so, what would a static top-level interface mean to you?
[ July 29, 2005: Message edited by: Barry Gaunt ]

Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
ankur rathi
Ranch Hand

Joined: Oct 11, 2004
Posts: 3830
I am surprise, interface means something that is abstract and abstract thing can't be static whether it is inner or outer. It was just my thought. But it is not true, am I not thinking in right way??

Thanks.
Arun Kumarr
Ranch Hand

Joined: May 16, 2005
Posts: 513

static interface { //Compiler error - But why??

static interface { //No compiler error
void m1();

}

void m2();

}
Arun Kumarr
Ranch Hand

Joined: May 16, 2005
Posts: 513

Sorry forgot to add the interface names!!!


static interface outer{ //Compiler error - But why??

static interface inner{ //No compiler error
void m1();

}

void m2();

}
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
Do you know what static *means* for a nested interface?

How would that meaning translate to toplevel interfaces?


The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Arun Kumarr
Ranch Hand

Joined: May 16, 2005
Posts: 513

Marking a class or an interface static at the top level is only to ensure that it can be accessed without an instance.
So having a interface marked as static at the class level would mean nothing as you can never instantiate your interface.

But..

Marking a interface which is inside a class ensures that the interface can be implemented/extended without having the actual instance of the toplevel enclosing class/interface.

Am I correct barry??
Layne Lund
Ranch Hand

Joined: Dec 06, 2001
Posts: 3061
Originally posted by Arun Kumarr:
Marking a class or an interface static at the top level is only to ensure that it can be accessed without an instance.
So having a interface marked as static at the class level would mean nothing as you can never instantiate your interface.

But..

Marking a interface which is inside a class ensures that the interface can be implemented/extended without having the actual instance of the toplevel enclosing class/interface.

Am I correct barry??


Neither top-level classes or interfaces can be declared static. What would this mean? Only nested elements can be declared static. Whether its a variable, method, nested class or interface, the meaning is similar: you don't need an instance of the outer class to access the nested element. This means that your later statement is on the mark. A static interface can be implemented or extended without an instance of the outer class or interface.

Layne


Java API Documentation
The Java Tutorial
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Static Interfaces