4 ms·
Sealed classes don't have to have anything in common. Sealed classes are an example of a discriminated union. A contrived example is you might have a function t
by NoSorryCannot 6y ago
Sealed classes don't have to have anything in common. Sealed classes are an example of a discriminated union. A contrived example is you might have a function that takes or returns circles or ducks but _nothing else_. Not triangles, not pigs. It has to be a circle or it has to quack.
Where are these used? Well, they are used in a sense all over the Java language already in the form of methods with checked exceptions, which say in their contract that they return either a successful result or any of the declared errors but nothing else.