Allowing inheritance with Records?

Brian Goetz brian.goetz at oracle.com
Thu Dec 28 16:38:40 UTC 2023


It depends what you mean by "inheritance".

Will records ever be able to extend an arbitrary class like 
SocketInputStream?  That's a pretty clear "definitely not."  Is there 
room for a more restricted category of abstract classes that records 
could extend without giving up their semantic benefits and safety 
guarantees?  Quite possibly, including perhaps the notion of "abstract 
record", which permits layered modeling but maintains the safety 
guarantees of records?

We explored abstract records during the design of records, and concluded 
that while they were a possibility, there are a number of details to 
work out, some of which are a little uncomfortable. (Separately, in 
Valhalla, we have explored what is required for an abstract class to be 
extendible by a value class, which might also inform an answer.)

So there is room to explore this further, but it is not currently a 
topic of active investigation.


On 12/28/2023 9:59 AM, Vikram Bakshi wrote:
> Hello,
>
> Is the decision to not allow inheritance for records set in stone? Or 
> will this be opened up and explored in the future?
>
> One of the goals of records (from Brian Goetz Devoxx talk) is to 
> "model data as data", and allowing inheritance would offer a powerful 
> way of modelling data.
>
> Right now we have to write interfaces for fields which are 
> shared/static methods for shared behaviour/copying and pasting - which 
> I do not think is ideal.
>
> Regards,
> Vikram
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/amber-dev/attachments/20231228/eafca2f4/attachment.htm>


More information about the amber-dev mailing list