<div dir="auto">Hello! <div dir="auto"><br></div><div dir="auto">No, I don't think that we should assume any semantics there. Just pass empty array always. Arguments can be passed to main() method if String[] args parameter is present, like always.</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Fri, Jul 5, 2024, 17:14 Brian Goetz <<a href="mailto:brian.goetz@oracle.com">brian.goetz@oracle.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">It is reasonable to infer the semantics of a no-arg constructor as “give me a default-configured instance of this class”, where default-configured is controlled by the class. This is done by Javabeans, serialization, test frameworks, and other frameworks. But once a constructor has arguments, those arguments have semantics. Can we really assume that a `String…` constructor is intended to be used with command-line-argument strings? That seems more of a leap.<br>
<br>
We do so with `main` because by longstanding convention, `main` functions/methods (going back to C) have been associated with the interface from the OS launcher to the program. But I think that’s as far as we should take it?<br>
<br>
> On Jul 5, 2024, at 11:05 AM, Tagir Valeev <<a href="mailto:amaembo@gmail.com" target="_blank" rel="noreferrer">amaembo@gmail.com</a>> wrote:<br>
> <br>
> Hello!<br>
> <br>
> I wonder if we should enable instance main method if the class has only vararg constructor:<br>
> <br>
> class Test {<br>
> Test(String... data) {<br>
> }<br>
> <br>
> void main() {<br>
> System.out.println("Hello World!");<br>
> }<br>
> }<br>
> <br>
> Java 22 doesn't like it:<br>
> > \jdks\jdk-22\bin\java.exe --enable-preview Test.java<br>
> error: can't find no argument constructor in class: Test<br>
> <br>
> However, in other contexts, such a class is considered as a class that has no-arg constructor. E.g., we can subclass it without explicit super-constructor invocation:<br>
> <br>
> class Test {<br>
> Test(String... data) {<br>
> }<br>
> <br>
> static class Use extends Test {}<br>
> }<br>
> <br>
> Would it be consistent to allow launching such classes?<br>
> <br>
> With best regards,<br>
> Tagir Valeev<br>
<br>
</blockquote></div>