Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import kotlin.contracts.ExperimentalContracts
- import kotlin.contracts.contract
- open class Base
- class ChildOne: Base() {
- fun childOneFunc() {
- println("salut")
- }
- }
- class ChildTwo: Base()
- @OptIn(ExperimentalContracts::class)
- fun funcThatExitsIfNotChildTwo(inst: Base) {
- contract {
- returns() implies (inst is ChildOne)
- }
- if (inst !is ChildOne) {
- error("nu e")
- }
- }
- fun main() {
- val inst: Base = ChildOne()
- funcThatExitsIfNotChildTwo(inst)
- inst.childOneFunc()
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement