What is the difference between sealed class vs sealed interface in kotlin

A major reason to choose to use a sealed class instead of interface would be if there is common property/function that you don’t want to be public. All members of an interface are always public. The restriction that members must be public can be worked around on an interface using extension functions/properties, but only if … Read more

What is the point of extending a sealed class with a non-sealed class?

Because in real-world APIs, sometimes we want to support specific extension points while restricting others. The Shape examples are not particularly evocative, though, which is why it might seem an odd thing to allow. Sealed classes are about having finer control over who can extend a given extensible type. There are several reasons you might … Read more

What are sealed classes in Java 17?

You can follow this link for examples. In short sealed classes gives you the control of which models, classes etc. that can implement or extend that class/interface. Example from the link: public sealed interface Service permits Car, Truck { int getMaxServiceIntervalInMonths(); default int getMaxDistanceBetweenServicesInKilometers() { return 100000; } } This interface only permits Car and … Read more