• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Static Interfaces

 
Ranch Hand
Posts: 662
Eclipse IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why is that the enclosing interface cannot be marked static whereas the enclosed interface can be marked static?

Any comments!!!
 
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


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 ]
 
Ranch Hand
Posts: 3852
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 662
Eclipse IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
static interface { //Compiler error - But why??

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

}

void m2();

}
 
Arun Kumarr
Ranch Hand
Posts: 662
Eclipse IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry forgot to add the interface names!!!


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

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

}

void m2();

}
 
author
Posts: 14112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Do you know what static *means* for a nested interface?

How would that meaning translate to toplevel interfaces?
 
Arun Kumarr
Ranch Hand
Posts: 662
Eclipse IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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??
 
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
 
First, you drop a couch from the plane, THEN you surf it. Here, take this tiny ad with you:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic