| 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
|
|
|
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
|
|
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
|
 |
 |
|
|
subject: Interface Query
|
|
|