Last active
September 2, 2016 13:44
-
-
Save kmizu/8bd8f1b3b4a97bd2b100f3dc621ecbe0 to your computer and use it in GitHub Desktop.
Type unsoundness of Kotlin
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ kotlinc Main.kt | |
$ kotlin MainKt | |
Exception in thread "main" java.lang.ClassCastException: java.lang.Object cannot be cast to B | |
at B.compareTo(Main.kt:4) | |
at MainKt.main(Main.kt:9) | |
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) | |
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) | |
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) | |
at java.lang.reflect.Method.invoke(Method.java:498) | |
at org.jetbrains.kotlin.runner.AbstractRunner.run(runners.kt:60) | |
at org.jetbrains.kotlin.runner.Main.run(Main.kt:99) | |
at org.jetbrains.kotlin.runner.Main.main(Main.kt:104) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
open class A() { | |
open fun compareTo(o: Any): Int = 0 | |
} | |
class B() : A(), Comparable<B> { | |
override fun compareTo(o: B): Int = 0 | |
} | |
fun main(args: Array<String>) { | |
println(B().compareTo(Object())) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment