Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Interesting. Even in Perl we cache and garbage-collect anon classes.

(The caching is for the very common case of creating a subclass with optional roles applied:

    my $class = Some::Meta::Class->create_anon_class(
        superclasses => ['Foo'],
        roles        => [qw/Commonly Applied Traits/],
    );
There is almost no speed hit the second time you create an instance of "Foo" with "Commonly", "Applied", and "Traits" applied. Not sure this would be useful for Java, although we can achieve the same effect as in the article.)



perl has a more stable vm than java :)

I like this trick though, it will help me with my seaside clone in java :)


FWIW, this is all done in "user space". The metaclass instance is attached to every instance that it creates. When all the instances go away, there are no more references to the metaclass, and it gets reclaimed. The destructor handles deleting the symbol table entries that were added, and that's that.

There is something to be said for not baking things into the language.




Consider applying for YC's Fall 2025 batch! Applications are open till Aug 4

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: