In my previous post on Anonymous Classes I erroneously referred to them as “dynamic objects” (thanks to commentors for pulling me up on that). Dynamic objects are something else entirely (although what precisely they might mean can vary on different platforms and in different languages). I have now corrected that post on this point, and also on another point that Marc Hoffman called me out on (again, thanks for that). And so the time has now come to expose the true identity of these so called “Anonymous Classes”.
There is another use case for anonymous classes, even simpler than that of providing implementations of interfaces: Anonymous POCO’s.
A few years ago (2011 to be precise) someone asked a question on StackOverflow about support for anonymous classes in Delphi. The reason for the question was that the poster was trying to use Delphi to develop for Android and on that platform the widespread use of callback interfaces makes anonymous classes highly desirable.