This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
I didn't look up the definition of useful, but I imagine it's broad enough to cover most occasions when a thing contributes to the accomplishment of an objective desired by the user. Inner classes can be used, they don't have to be, to accomplish the programmer's objectives, so they're useful. Further, the programmer wouldn't use inner classes if they weren't 'useful.' You either need to define what you mean by useful or accept the fact that they just are.
Always learning Java, currently using Eclipse on Fedora.
Linux user#: 501795
Lalit Mehra wrote:but just for some requirements you need some generic functionality and you do not want to put that in the Dog class
You say its a generic functionality and want to create an Inner class for that? How would other classes make use of the Generic functionality? If there are no other classes using this- then its not a generic functionality.
Lalit Mehra wrote: brother i have explicitly written (inner class) please check ...
Though it can be implemented. I feel its Not real world situation example. And do you think the example you have provided is useful?
Lalit Mehra wrote:
anyways ... just for the sake of providing real world examples ... go through the java API documentation for Collections and Generics ... JAVA API
How would Java API provide example for Inner classes? If at all you would ask to refer to the source code- that might have been useful
Rahul, I could just recall that- Lot of places in JDK source code inner classes have been used. You might want to check the Stream related classes in Java IO package (Not sure about the exact classes which use them, someone might be able to point few example classes which use).