Are inner classes commonly used in Java? Are they "bad"?

johnny picture johnny · Jun 22, 2009 · Viewed 14.9k times · Source

Are inner classes commonly used in Java? Are these the same as nested classes? Or have these been replaced in Java by something better? I have a book on version 5 and it has an example using an inner class, but I thought I read somewere that inner classes were "bad."

I have no idea and was hoping for thoughts on it.

Thank you.

Answer

Daniel Earwicker picture Daniel Earwicker · Jun 22, 2009

Inner classes are frequently used, and something very similar - anonymous classes - are practically indispensable, as they are the closest thing Java has to closures. So if you can't remember where you heard that inner classes are bad, try to forget about it!