Allow sealed interfaces without subclasses
Jakob Brünker
jakob.bruenker at gmail.com
Thu Nov 26 09:55:32 UTC 2020
> And once Valhalla will be integrated, a primitive object type with no
field and a private constructor is a unit type that even disallows null.
Thanks, I didn't know you could do that in Valhalla, that sounds promising
> A final class with a private constructor is what you are looking for.
> Like we have java.lang.Void
True; My fear is this: Brian Goetz's writeup on pattern matching (
https://cr.openjdk.java.net/~briangoetz/amber/pattern-match.html) talks
about and https://openjdk.java.net/jeps/8213076 touches on exhaustiveness
checking. I'm afraid that an exhaustiveness checker won't know that all
constructors are private or, if it does, won't know that the private
constructors are never called inside the class.
I could be wrong about that, which would be great, though in that case,
while it would lessen the need for a sealed interface without subclasses, I
still don't see a reason to disallow it.
Ciao,
Jakob
More information about the amber-dev
mailing list