<div dir="auto">I was reading the discussions on "anonymous class declarations" which in my understanding simply means that the file scope is treated as class scope of a class named after the file. It was also mentioned that those classes would not be accessible for other source files to reference. <div dir="auto"><br></div><div dir="auto">My question is then why should we treat them so special?</div><div dir="auto">The class name is already strongly coupled to the file name except for package private classes in a file. </div><div dir="auto"><br></div><div dir="auto">Why not treat them as regular classes with fields and instances and all?</div><div dir="auto"><br></div><div dir="auto">The only reason I see is to make static variables and the static of main implicit which is a weak argument for treating these classes so special in my opinion. </div><div dir="auto"><br></div><div dir="auto">If we treat them as regular classes it would even be possible to have generics or inheritance with an optional partial class header syntax like for example:</div><div dir="auto">//file HelloWorld.java</div><div dir="auto">import xyz;</div><div dir="auto"><br></div><div dir="auto">class <T> implements AutoClosable;</div><div dir="auto"><br></div><div dir="auto">private T t;</div><div dir="auto"><br></div><div dir="auto">@Override</div><div dir="auto">public void close() {} </div><div dir="auto"><br></div><div dir="auto">static int myGlobal = 5;</div><div dir="auto"><br></div><div dir="auto">static void main() {</div><div dir="auto"><span style="white-space:pre">      </span>myGlobal = 51;</div><div dir="auto"><span style="white-space:pre">   </span>var hello = new HelloWorld<Integer>(); </div><div dir="auto"><span style="white-space:pre">   </span>hello.t = myGlobal;</div><div dir="auto"><span style="white-space:pre">      </span>hello.close();</div><div dir="auto">}</div><div dir="auto"><br></div><div dir="auto">I just think by restricting the implicit class scope to only be useful for entry points it makes it a weak feature while restricting many other use cases. </div><div dir="auto"><br></div><div dir="auto">Great regards </div><div dir="auto">RedIODev </div></div>