File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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

Interface Query

Ankur Mahajan

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

Joined: Oct 02, 2003
Posts: 11312

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

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

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

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

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

Joined: Oct 27, 2005
Posts: 19693

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.

How To Ask Questions How To Answer Questions
I agree. Here's the link:
subject: Interface Query