JEP 445
Red IO
redio.development at gmail.com
Tue Apr 11 04:56:25 UTC 2023
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.
My question is then why should we treat them so special?
The class name is already strongly coupled to the file name except for
package private classes in a file.
Why not treat them as regular classes with fields and instances and all?
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.
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:
//file HelloWorld.java
import xyz;
class <T> implements AutoClosable;
private T t;
@Override
public void close() {}
static int myGlobal = 5;
static void main() {
myGlobal = 51;
var hello = new HelloWorld<Integer>();
hello.t = myGlobal;
hello.close();
}
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.
Great regards
RedIODev
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/amber-dev/attachments/20230411/9c9edb2f/attachment.htm>
More information about the amber-dev
mailing list