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.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…