Where does this array come from ?

Brian Goetz brian.goetz at oracle.com
Wed Apr 8 13:25:16 UTC 2020


These are two separate issues; we can have inline records “now”, since Record meets the requirements as an abstract base class for inlines.  

That said, now that we’ve worked through the details for inline classes (which, not only had we not done at the time we designed records, but we’d assumed that there would be no way they could extend abstract classes), it is reasonable to revisit this question now.  (This would likely mean making Record an interface, rather than a class; this had been discussed earlier when we didn’t think we could make inlines extend abstract classes, but that discussion got dropped at that point.)

> Could we allow record classes to extend abstract stateless classes (same as
> in valhalla) that also extend java.lang.Record.
> 
> I think that such functionality is needed (at least in JVM view) for inline
> records.
> 
> Should it also be made available to non-inline records?
> 
> Thanks,
> Mateusz
> 
> 
> 
> On Tuesday, April 7, 2020, Remi Forax <forax at univ-mlv.fr> wrote:
>> Create an an interface with a default method toJSON().
>> 
>> interface DeriveJSON {
>>  public default String toJSON() {
>>    // use an object mapper or whatever you want here
>>  }
>> }
>> 
>> so when you want a Point with a method toJSON(), you can write
>>  record Point(x, y) implements DeriveJSON { }
>> 
>> With a little work, you can make toJSON to use a polymorphic inlining
> cache (good for benchmark) and with the upcoming hidden classes have a
> constant cost if it becomes megamorphic without generating bytecode.
>> 
>> Rémi
>> 
>> ----- Mail original -----
>>> De: "Stephen Colebourne" <scolebourne at joda.org>
>>> À: "amber-dev" <amber-dev at openjdk.java.net>
>>> Envoyé: Lundi 6 Avril 2020 15:45:48
>>> Objet: Re: Where does this array come from ?
>> 
>>> FWIW, a colleague has previously argued that the toString of a bean
>>> should be JSON. At a company he worked at, all their beans were JSON
>>> and it apparently allowed them to build tooling on top of the
>>> toString. I'm not sure I'm convinced about JSON, but I do think a
>>> record is closer to a map than a list. And yes, Joda-Beans uses {} not
>>> [].
>>> Stephen
>>> 
>>> 
>>> On Mon, 6 Apr 2020 at 14:01, Brian Goetz <brian.goetz at oracle.com> wrote:
>>>> 
>>>> Perhaps we should rotate the punctuation every version just to
> discourage
>>>> parsing :)
>>>> 
>>>>> On Apr 6, 2020, at 7:34 AM, Remi Forax <forax at univ-mlv.fr> wrote:
>>>>> 
>>>>> I've was debugging a code yesterday that was printing
>>>>> Empty[]
>>>>> 
>>>>> After some head scratching, trying to find an array of Empty, i found
> that it
>>>>> was just an empty record
>>>>> record Empty() { }
>>>>> 
>>>>> This is another clue that using square brackets for toString() is a
> bad idea !
>>>>> 
>>>>> regards,
>>>>> Rémi
>> 



More information about the amber-dev mailing list