2 ms·
Of course they can! They can implement interfaces, which are sealed. In fact, that's one of their most common usages: sealed interface Option { re
by pron 4y ago
Of course they can! They can implement interfaces, which are sealed. In fact, that's one of their most common usages:
sealed interface Option {
record InputFile(Path path) implements Option {}
record OutputFile(Path path) implements Option {}
record MaxLines(int maxLines) implements Option {}
record PrintLineNumbers() implements Option {}
}
(see https://www.infoq.com/articles/data-oriented-programming-java/ https://www.infoq.com/articles/data-oriented-programming-jav...)
The problem of extending classes is that it can introduce hidden state and also result in non-reflexive equality. But interfaces are fine.
- sixbrx 4y agoThanks for that, I knew I must have been missing something!