GeeCON Prague 2014*
The moose likes Beginning Java and the fly likes Interface Query Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Interface Query" Watch "Interface Query" New topic
Author

Interface Query

Ankur Mahajan
Greenhorn

Joined: Feb 03, 2008
Posts: 8
Is it possible to declare one interface within another?
If yes then why and if no then why not.
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11356
    
  16

have you tried it? What happened?


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39084
    
  23
Welcome to the Ranch.

Look in the Java Language Specification. Look at first at Section 6.4.4
Ankur Mahajan
Greenhorn

Joined: Feb 03, 2008
Posts: 8
Yes I have tried it and it is allowing to declare one interface within another but when I implement that interface in a class, it does not give error for "unimplemented methods" of inner interface.

but at first place why it is allowing to declare an interface inside another.
Ankur Mahajan
Greenhorn

Joined: Feb 03, 2008
Posts: 8
hey Campbell

According to specifications it can be done.
But can you tell,where it can be useful or when such declaration is needed.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19697
    
  20

Check out java.util.Map and java.util.Map.Entry.

Map.Entry is an interface that only makes sense in the context of a Map. Declaring it as an inner interface creates a form of coupling between the two interfaces.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
 
GeeCON Prague 2014
 
subject: Interface Query