Comment by weksf54
3 months ago
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:
package com.example.vehicles;
public sealed interface Vehicle
// The permits clause has been omitted
// as its permitted classes have been
// defined in the same file.
{ }
record Truck(int loadCapacity) implements Vehicle {}
record Car(int numberOfSeats, String brandName) implements Vehicle {}
No comments yet
Contribute on Hacker News ↗