Campbell Ritchie wrote:Welcome to the Ranch Adam Miller
ramakrishna rayudu wrote:can you give me any idea in which case i need to write the class with in another class.
and what is the difference between static inner class and nested class
can you give me any example where i need to use these concepts in real world.
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
Winston Gutkowski wrote:There are 4 specific types of class that people often refer to as "inner":
1. Static nested classes - As satish said, these are just like any other class; they just happen to be defined inside another one. 2. Non-static nested classes - These are far less common, and are often used to create an Adapter, where the implementation of the inner class is dependant on its outer one. They are also usually private. Java 'collection' classes use them a lot to define Iterators and "views" (eg, Map.keySet()) to the backing collection.
These two together, comprise "nested" classes.
Mike Simmons wrote:I found a real-world use for a named local class exactly once in my career so far, and I was pleasantly surprised. But I'll be very surprised to find another.
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
Mike Simmons wrote:Sure - it was in a record-parsing method, where the objective was to extract a group of fixed-length fields from a single fixed-length record....
A static member class would have worked fine, but would have had a wider scope than it really needed. And I would have had to add a bytes field, and a constructor, just to provide access to the local variable bytes that the local class already has access to. The parsing rules were specific to this particular record type, and I didn't find a need to generalize the class any further.
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
Regards
KumarRaja
Kumar Raja wrote:I don't mean to hijack this thread, but since my question is related to static nested class and inner class, thought of asking my question here instead of starting a new thread.
In my code, which is a file generator program, I have used some non static inner classes for value objects, comparators etc. The file generator program is ideally a message listener and will be start creating the files based on the event it receives.
So far, my code is working fine without any issues. However, when we ran FindBugs, it complained about the usage of non static inner class and recommends the usage of static nested class. I agree that outer class uses my inner classes and inner classes do not have any explicit reference of outer class.
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
Kumar Raja wrote:Actually now I have more questions on this topic, after seeing your reply. Instead of confusing the original poster, I will ask this question in an another thread which I opened here
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here