aspose file tools
The moose likes Beginning Java and the fly likes Interface Query Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Beginning Java
Reply 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: 9950
    
    6

have you tried it? What happened?


Never ascribe to malice that which can be adequately explained by stupidity.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 32689
    
    4
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: 19216

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
How To Ask Questions How To Answer Questions
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: Interface Query
 
Similar Threads
SessionContext Interface question
getServletContext() method?
access modifier of interface method
JDBC Connection Interface
Java