3 ms·
The JEP for this is worth mentioning: https://openjdk.org/jeps/445 https://openjdk.org/jeps/445 This is a preview feature that still requires the --enable-prev
by TheCycoONE 3y ago
The JEP for this is worth mentioning: https://openjdk.org/jeps/445 https://openjdk.org/jeps/445
This is a preview feature that still requires the --enable-preview flag. It's meant to reduce the initial cognitive load when teaching programming rather than an embrace of terse syntax.
- BulgarianIdiot 3y agoIf they wanted that, they'd allow top-level code, instead of this weird halfway method of doing it.
- kaba0 3y agoWhich would have zero benefits, and would require more knowledge on the exact specifics of the language. (Eg. is it a local variable of a field? The two has very different semantics).
- Gunax 3y agoSo how this works is interesting. I assumed they were just making any method called 'main' sugar for public static void. But it's not that way. Instead, apparently the proposal is to allow for main to be an instance method. Additionally, we are getting anonymous classes. Because methods can share names (both between inheritance and with different args) we apparently get a warning if a superclass also has a static main being overridden with an instance main. I would have preferred if this was simply an error.
- Traubenfuchs 3y ago> the proposal is to allow for main to be an instance method An instance method of... which instance? Is some invisible, nameless class instantiated with its default constructor? How would you acquire this main method via reflection?
- kaba0 3y agoImagine `public class [randomName] {` at the top. If it has a void main() method the class loader (not the spec!) will do new [randomName].main() You won’t acquire this main via reflection because why would you do so? It is for teaching, and one-off scripts. Later on you can trivially add that single line and name your class.