Fwd: Records feedback

Brian Goetz brian.goetz at oracle.com
Thu Oct 1 20:33:28 UTC 2020

Received on the -comments list.

A similar comment was made in the comments of this SO issue:

-------- Forwarded Message --------
Subject: 	Records feedback
Date: 	Thu, 1 Oct 2020 15:09:38 -0500
From: 	David Aaron Kaye <kayedavi at gmail.com>
To: 	java-se-spec-comments at openjdk.java.net

Good afternoon,

I am very excited to see Records coming to Java. I have been playing around
with them since JDK 14. I noticed that in the proposal, JDK-8246771
<https://bugs.openjdk.java.net/browse/JDK-8246771>, it says

...if the canonical constructor is explicitly declared then its access
modifier must provide at least as much access as the record class

I have implemented a functional List:

public sealed interface List<A> permits Cons, Nil {

public record Cons<A>(A head, List<A> tail) implements List<A> {

public record Nil<Nothing>() implements List<Nothing> {
public static final Nil instance = new Nil();

private Nil() {

I made the constructor private because I want this to be a singleton,
accessed from instance, but the current proposal does not allow me to do
that, and I get a compilation error on the private constructor. I could
prefer to be able to make the constructor private so that I can have a
record that is a singleton.


David Kaye
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.java.net/pipermail/amber-spec-experts/attachments/20201001/942f60cc/attachment.htm>

More information about the amber-spec-experts mailing list