Is there a way to extend unnamed classes to somehow facilitate top level static methods in Java?

Julian Waters tanksherman27 at gmail.com
Wed Oct 18 03:34:23 UTC 2023


Hi all,

Quick question: Java is often criticized for having too much emphasis on
Object Oriented Programming, with every method having to be marked static
repeatedly if one wants to opt out of OOP. Recently, unnamed classes and
instance main methods were released into Java 21, which got me thinking:
Can we somehow use them (unnamed classes) to facilitate top level
"classless" methods in Java? Obviously, the methods would in actuality
belong to the unnamed class and aren't actually classless, and internally
would be static to avoid relying on object instances (since they're
supposed to be top level). Whether or not we'd want to support top level
global variables this way too I leave up to discussion. Or maybe there's a
different way to have free form methods (such as with Kotlin) without
having to mark entire utility classes as static somehow?

Thoughts?

best regards,
Julian
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/amber-dev/attachments/20231018/679d6c0f/attachment.htm>


More information about the amber-dev mailing list