<div dir="auto"><div>I can't comment on the first point, but the second point won't work.</div><div dir="auto">The syntax you suggested creates at best an order of declaration dependency between the entry point and the instance initialized block, and at worst an ambiguity to the compiler.</div><div dir="auto"><br></div><div dir="auto">Also, I believe that in the current solution it is possible to import in an unnamed main class.</div><div dir="auto"><br><div class="gmail_quote" dir="auto"><div dir="ltr" class="gmail_attr">On Thu, Apr 13, 2023, 18:49 Andrew Evers <<a href="mailto:andrew.evers@gmail.com">andrew.evers@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Hi,<div><br></div><div>I really like the idea of reducing the amount of boilerplate required to get to a simple Java program. </div><div><br>Two comments:</div><div>1. Would it be at all possible to consider a main that returns int? Operating systems that don't support it are free to disregard it, and it feels better than System.exit(). It also allows skipping the idea of void, which is somewhat of a holdover from C.</div><div>2. I have an idea for a slightly different approach to the problem that may solve a few of the problems being proposed, and allows for imports, which would make it more useful for scripting use cases. </div><div><br></div><div>Here are three examples showing the syntax.</div><div><br></div><div>Example 1:</div><div>{</div><div>  System.out.println("Hello, World");</div><div>}</div><div><br></div><div>Example 2:<br></div><div>import java.nio.*;<br></div><div><br></div><div>{</div><div>  Path filePath = Path.of("file.txt");</div><div>  String fileContent = new String(Files.readAllBytes(filePath));</div><div>  System.out.println("Content is " + fileContent);<br></div><div>}</div><div><br></div><div>Example 3:<br></div><div>import java.nio.*;<br></div><div><br></div><div>{<br></div><div><div>  Path filePath = Path.of("file.txt");</div><div>  String fileContent = new String(Files.readAllBytes(filePath));</div><div>  greet(fileContent);<br></div><div>}</div></div><div><br></div><div>void greet(String s)</div><div>{</div><div><div>  System.out.println("Content is " + s);</div></div><div>}</div><div><br></div><div>The rules are simple:</div><div>1. If the first non-whitespace is a {, then treat it as the block defining the method public static void main(String [] args).</div><div>2. If the first non-whitespace is "import" then capture the imports.</div><div>3. If there is non-whitespace after the closing } in the main block, include it before the class closing brace.</div><div><br></div><div>That is:</div><div><br></div><div>// import statements if any</div><div>class Main  </div><div>{</div><div>  public static void main(String [] args) </div><div>  { // Content including { from source </div><div>  } // end of content, including }</div><div><br></div><div>  // Content after closing } in source, if any.</div><div>}</div><div><br></div><div>There are some minor fixups required on line numbers after the import statements, these can be overcome by either ensuring that the additional code takes up zero lines, or by fixing up the output of the compiler.</div><div><br></div><div>Regards,</div><div><br></div><div>Andrew.</div><div><br></div></div>
</blockquote></div></div></div>