News for hackers. Stuff that matters.
Re:Project Loom and Structured Concurrency by pron on Saturday December 05, 2020 @12:05PM (#25316111)
> Can records implement interfaces?

Yes.

> Can records be variants in a sealed class hierarchy?

Yes.

> Can records have a private primary constructor?

The accessibility of the constructor is roughly at least that of the record class itself. If the record class is public, then the canonical constructor must be public. However, thanks to the positive answers to the two previous questions, you can have a readable-though-not-publicly-constructible record -- make it a private implementation of a sealed public interface.

> Can I customize the getters (to e.g., make defensive copies)?

Yes. Although in most cases, defensive copying in the constructor is sufficient.

There are no comments on this comment yet.