• Post Reply Bookmark Topic Watch Topic
  • New Topic

what is the need of writing an inner class inside an interface or abstract class  RSS feed

 
saikrishna cinux
Ranch Hand
Posts: 689
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
what is the neccesity of writing an inner class inside a abstrac class or in an interface?
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
None whatsoever that I know of. Why would anyone think there is a necessity here?
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16059
88
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just because it's possible to do this in Java doesn't mean it's necessary.

I can also turn the question around: Is there a reason why it should not be possible to have inner classes in abstract classes or interfaces?
[ September 04, 2006: Message edited by: Jesper Young ]
 
Jan Groth
Ranch Hand
Posts: 456
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
well, i can have code in abstract classes. so why shouldn't i use inner classer to implement my what-so-ever-code?

absolutely no question that this can make sense (for me ;-)

looks different with interfaces. actually i would have thought that you can't do it...

jan
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
[Jan]: looks different with interfaces. actually i would have thought that you can't do it...

You can't, in the sense that any class nested in an interface is implicitly static, and therefore not an inner class, by definition.

It's certainly possible to define an interface nested within another interface, and it may be perfectly natural to do so. Take a look at Map.Entry - the Entry interface is intended to be used in collaboration with the Map interface; it has no real use otherwise. So it makes sense to define Entry with Map. Nothing wrong with that. However I don't belive it is ever necessary to do something like this.

I'm not sure what the real intent of this question was. Seems very strange to me.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!