Scope for JEP 468: Derived record creation
Gavin Bierman
gavin.bierman at oracle.com
Fri Mar 1 17:37:51 UTC 2024
On 1 Mar 2024, at 00:02, Swaranga Sarma <sarma.swaranga at gmail.com> wrote:
Thank you.
>it's a pretty verbose syntax
Agreed. I was trying to stay close to the current syntax but even more concise could be: R r = {a: 1, b: 2}. But the question was not about the syntax.
Right, but that’s a record literal. As Brian says on another thread, we have plans to look at this when we come to look at other new literal forms. (So many things in the pipeline!)
Thanks,
Gavin
> it makes it harder to refactor from records to classes
Wouldn't the current JEP also have the same limitations? Although I do see the JEP mention that it may be possible in the future for regular classes.
Regards
Swaranga
On Thu, Feb 29, 2024 at 3:11 PM Brian Goetz <brian.goetz at oracle.com<mailto:brian.goetz at oracle.com>> wrote:
While such a feature is possible, I am not particularly excited about it for several reasons. If the goal is "I want to construct using named instead of position arguments" (which I think is your goal), it's a pretty verbose syntax; a better one would be
new R(a: 1, b: 2)
But that's a much smaller concern. The bigger one is that I don't think the language is improved by having a named parameter mechanism for records, but for nothing else (not for instantiating class instances, not for invoking methods.) While it might seem "better than nothing", having two different ways to do something, but one of them only works in narrow situations, is as likely to be frustrating than beneficial. If the payoff is big enough, then it might be a possibility, but "invocation by parameter name" is nowhere near that bar.
Finally, if it works for records but not for classes, it makes it harder to refactor from records to classes, since there will be use sites that have to be adjusted.
So I think for the time being, the answer is "no", though if we run out of things to work on, we might reconsider.
On 2/29/2024 4:34 PM, Swaranga Sarma wrote:
The JEP looks really promising. However I am wondering if there will be a separate JEP for creating new records from scratch with similar syntax.
The current JEP states that its goals are to enable creating records from an existing record and for that it seems sufficient. But I would also love to be able to create new records from scratch using the same syntax. Something like:
var circle = new Circle with {
radius = 0.5f;
center = new Center with {
x = 0;
y = -1;
z = 8;
};
};
Originally I had asked Brian Goetz about record literals and they seemed like a possibility but withers seem like a more general feature so I am hoping something like this would be supported in the future.
Regards
Swaranga Sarma
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/amber-dev/attachments/20240301/fba98b2f/attachment-0001.htm>
More information about the amber-dev
mailing list