Make records not implicitly final
Remi Forax
forax at univ-mlv.fr
Mon Feb 10 20:48:43 UTC 2020
----- Mail original -----
> De: "Samuel Andrés" <samuel.maurice.andres at gmail.com>
> À: "amber-dev" <amber-dev at openjdk.java.net>
> Envoyé: Samedi 8 Février 2020 17:45:46
> Objet: Make records not implicitly final
> Hi to all,
>
Hi Samuel,
> I hope this is the correct place for comment about Records.
>
> I saw discussions about extension of records here (
> https://cr.openjdk.java.net/~briangoetz/amber/datum.html ) leading to
> the conclusion that "we should hold this possibility in reserve". I
> understand the main reasons to make records implicitly final and not
> extensible.
>
> Nevertheless, stuctures like records could also be very useful for
> modelling purposes if they would be extensible.
Hum, modelling doesn't require inheritance.
> May be the usage could lead to a compromise on this point (for example, generating default
> equals() / hashCode() implementations, only for explicitly final
> records, using all the members of the parent class hierarchy). I am not
> a language specialist, but I share my point of view, just in case...
We had a kind of similar discussion (you can browse the spec-expert list for more info).
The idea is that you don't need inheritance to be able to specify that several "structures" share the same components, an interface is enough.
So instead of
abstract record Base(int age) {}
final record Person(String name, int age) extends Base(age) {}
you can write
interface Base {
int age();
}
record Person(String name, int age) implements Base {}
This avoid to introduce the concept of abstract record (or its dual final record) in the language which is a huge win in term of simplicity.
[...]
>
> Thanks for reading. I'm sorry for my bad english.
>
> Samuel Andrés
regards,
Rémi
More information about the amber-dev
mailing list