Introduction of sealed classes
Sealed classes can be derived only by their own inner classes or objects. Their constructors cannot be called explicitly, so compiler knows all their descendants. Incompatible modifier checks (final, abstract). Impossible with interface, object, enum. A pack of tests provided.
This commit is contained in:
@@ -0,0 +1,9 @@
|
||||
sealed class Sealed(val x: Int) {
|
||||
object First: Sealed(12)
|
||||
open class NonFirst(x: Int, val y: Int): Sealed(x) {
|
||||
object Second: NonFirst(34, 2)
|
||||
object Third: NonFirst(56, 3)
|
||||
// It's ALLOWED to inherit Sealed also here
|
||||
object Fourth: Sealed(78)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user