Comment by vips7L
3 months ago
You implemented this much more verbosely than needed
sealed interface Vehicle {
record Truck(int loadCapacity) implements Vehicle {}
record Car(int numberOfSeats, String brandName) implements Vehicle {}
}
Ah! Thanks, I didn't know that. I should have RTFMD better - https://docs.oracle.com/en/java/javase/21/language/sealed-cl...
Turns out you can do this and not have the annoying inner class e.g. Vehicle.Car too: