Hi all, What are differencess between non-static inner class, static inner class, local class and anonymous class thanks daniel
posted 14 years ago
The main difference between static and non-static inner class is that in the first case, you need to have a reference to the outer class if you want to handle the inner class (in case it is public). Public static inner classes are of interest if you want for example to add a unit testing code to you class.
There are two interesting point: The first one is that the code are generated in two files Toto.class and Toto$TotoTest.class, so that they can be sorted out when deployed. And the second one, is that you only have to call java TotoTest.class to run you unit test.
Non-static Inner classes are often used for "inner use", as for listener implementation for example.
With such a way to proceed the class and the listeners are tighly coupled (which may or may not be advantageous). You could also have used an anonymous class if you do not feel the need to create more instances of MyActionListener. The class implementation is directly given as method argument.
Hope this helps. W. [This message has been edited by Wilfried LAURENT (edited September 28, 2001).] [This message has been edited by Cindy Glass (edited September 28, 2001).]