Minor question about a `MyVal.default`-like syntax
Kevin Bourrillion
kevinb at google.com
Fri Jun 2 21:46:40 UTC 2023
This is not too important right now, but I had thoughts, so...
On Thu, Jun 1, 2023 at 10:59 AM Brian Goetz <brian.goetz at oracle.com> wrote:
Users should be able to say `new Complex()` and get a default complex
> value. (Maybe they can also say `Complex.default`; maybe we won't need
> that.) And the same for reflection.
>
I think the argument for `MyVal.default` being *unnecessary* might go like
this:
* either there's no implicit constructor and `MyVal.default` won't work
* or there is, and `MyVal.default` would have to mean the same as `new
MyVal()`, so what's the point?
If that's correct, there might not be a strong argument for keeping it, but
I came up with a couple weak ones.
1. Arguably, its meaning is more apparent without the reader having to dig
into MyVal.java (how much does this matter, in this case?)
2. It *feels like* a well-known immutable value that just kind of "exists"
and has no need to be constructed. A constant. In fact people might feel
tempted to make such constants?
Note I do still approve of `public implicit MyVal();` and even of calling
that a "constructor", because it nearly enough plays that role. But
something about the term "implicit construction" doesn't seem right.
"Default initialization" seems more on point I guess.)
(Tangent: while the choice of keyword isn't that important right now, I
have already found myself saying "explicit implicit constructor" and then
frowning in momentary confusion :-))
--
Kevin Bourrillion | Java/Kotlin Ecosystem Team | Google, Inc. |
kevinb at google.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/valhalla-spec-experts/attachments/20230602/4f7c833d/attachment.htm>
More information about the valhalla-spec-experts
mailing list