vgrechka
10/10/2016, 8:36 AMfun testOverrideWithNothing() {
class A {
override fun toString(): String = throw Exception("Don't call toString() on A")
}
class B {
override fun toString()/*: Nothing*/ = throw Exception("Don't call toString() on B")
}
println("1) " + try {"" + A()} catch (e: Throwable) {"Died saying: ${e.message}"})
println("2) " + try {"" + B()} catch (e: Throwable) {"Died saying: ${e.message}"})
}
Output:
1) Died saying: Don't call toString() on A
2) Kotlin_jvm_playgroundKt$testOverrideWithNothing$B@6e0be858