Paving the on-ramp
Brian Goetz
brian.goetz at oracle.com
Thu Sep 29 14:01:19 UTC 2022
> Indeed, I intend that there are no explicit constructors or
> instance initializers here. (There can't be constructors, because
> the class is unnamed!)
>
>
> Hmm, I was under the impression I could drop all my `static`s while
> keeping the class signature if I wanted? But, if I can and even then
> explicit constrs and initers are banned, then indeed, at least one of
> my drawbacks is invalid. I don't think it undercuts my overall case
> that much.
Yes you can. Example:
class InstanceMain implements Serializable {
public InstanceMain() { }
public void main() { ... }
}
and if you `java InstanceMain`, the launcher will do `new
InstanceMain().main()`.
The two features -- no class header and instance main -- are
orthogonal. If you don't have a class header, you don't get explicit
constructors. If you use instance main, you must have a no-arg
constructor, which could be supplied explicitlly (if there is a class
header) or implicitly (whether or not there is a class header.)
>>
>> One or more class annotations could appear below package/imports?
>
> No package statement (unnamed classes live in the unnamed
> package), but imports are OK.
>
>
> I'm confused; what does any of this have to do with package location?
> Isn't that orthogonal to everything we're discussing?
There's a world where package is relevant here, but it seems pretty
esoteric. If you define a class with no name, the thing you want to do
with it is launch it directly. Seems like putting it in a package makes
little sense here.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/amber-spec-observers/attachments/20220929/1548b647/attachment.htm>
More information about the amber-spec-observers
mailing list