benleggiero
02/02/2017, 1:30 AMfun Array<*>.myInterfaceFunction() {}?ilya.gorbunov
02/02/2017, 1:33 AMbenleggiero
02/02/2017, 1:36 AMextension Int : Comparable<Int> {
public operator fun compareTo(other: Int): Int {
return if (this == other) 0 else if (this < other) -1 else 1
}
}
would just be:
fun Int.compareTo(other: Int): Int {
return if (this == other) 0 else if (this < other) -1 else 1
}
But then the compiler would allow Int to be passed anywhere a Comparable<Int> is acceptedilya.gorbunov
02/02/2017, 1:39 AMInt is already a Comparable<Int>, but let's imagine that it's not. What do you expect should happen when you pass Int where Comparable<Int> is expected? A wrapper that implements the required type to be created?benleggiero
02/02/2017, 1:40 AMbenleggiero
02/02/2017, 1:40 AMcompareTo() in Comparable<Int> would be resolved statically just like a normal extension functionilya.gorbunov
02/02/2017, 1:42 AMComparable<Int> doesn't know anything about that it should now search for compareTo statically instead of invoking it through the interfacebenleggiero
02/02/2017, 1:43 AMbenleggiero
02/02/2017, 1:43 AM