I just discovered local classes in Java:
public final class LocalClassTest
{
public static void main(final String[] args) {
for(int i = 10; i > 0; i
Local class is something used in some particular method and nowhere else.
Let me provide an example, I used a local class in my JPEG decoder/encoder, when I read configurations from the file which will determine further decoding process. It looked like this:
class DecodeConfig {
int compId;
int dcTableId;
int acTableId;
}
Basically it is just three int
s grouped together. I needed an array of configurations, that's why I couldn't use just an anonymous class. If I had been coding in C, I would've used a structure.
I could do this with an inner class, but all the decoding process is handled in a single method and I don't need to use configurations anywhere else. That's why a local class would be sufficient.
This is, of course, the most basic example, but it's from the real life.