You can actually declare classes in functions. In ...
# language-proposals
m
You can actually declare classes in functions. In Java they were called local classes. But I imagine declaring local objects might be problematic on bytecode level.