Allowing inheritance with Records?

Vikram Bakshi vab2048 at gmail.com
Fri Jan 5 10:37:50 UTC 2024


> 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?

This is pretty much what I was thinking. An abstract record can extend
either java.lang.record or another abstract record. The "non-abstract"
record would then extend the abstract one. Just like how we do now for
classes and abstract classes.

>   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.

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

 I hadn't even thought of the implications of valhalla. Even though it is
not an active topic of investigation, would you please share what the
uncomfortable details were? (I am asking out of sheer curiousity).

Glad to hear the idea has not been ruled out completely.

Thanks Brian,

Regards,
Vikram



Good to know it is a future possibility




On Thu, Dec 28, 2023 at 4:38 PM Brian Goetz <brian.goetz at oracle.com> wrote:

> 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/20240105/7305edc8/attachment.htm>


More information about the amber-dev mailing list