elect
03/27/2019, 4:18 PM@JvmName
cant do anything here?
@JvmName("getI") fun get(): Int = 0
@JvmName("getF") fun get(): Float = 0f // error, signature clash
diesieben07
03/27/2019, 4:19 PMdiesieben07
03/27/2019, 4:20 PMval foo = get()
What would the type of foo
be? Which version of get
would be called?elect
03/27/2019, 4:20 PMdiesieben07
03/27/2019, 4:21 PMelect
03/27/2019, 4:22 PMdiesieben07
03/27/2019, 4:23 PMfoo(get())
- Now the parameter type of foo
decides which version of get
I call. If at some point someone changes foo
from accepting just Float
and adds an overload for Int
you now suddenly have an incompatible change.diesieben07
03/27/2019, 4:23 PMelect
03/27/2019, 4:24 PMdiesieben07
03/27/2019, 4:24 PMelect
03/27/2019, 4:25 PMdiesieben07
03/27/2019, 4:26 PMdiesieben07
03/27/2019, 4:27 PMfoo
and get
can be in completely separate libraries. There is no way for the compiler to see this while writing foo
or get
, since they are not developed together.elect
03/27/2019, 4:27 PMinterface A {
fun foo() = 0
}
interface B {
fun foo() = 2
}
class C : A, B // C must implement foo
diesieben07
03/27/2019, 4:28 PMelect
03/27/2019, 4:28 PMelect
03/27/2019, 4:30 PMdiesieben07
03/27/2019, 4:30 PMelect
03/27/2019, 4:31 PMfoo(Float)
is fine, but if you have also foo(Int)
, then there is ambiguity. The compiler shall be told somehow which one use by the dev.elect
03/27/2019, 4:32 PMC
implements foo
elect
03/27/2019, 4:32 PMelect
03/27/2019, 4:33 PMelect
03/27/2019, 4:33 PMrobstoll
03/27/2019, 4:51 PMelect
03/27/2019, 4:52 PMelect
03/27/2019, 4:53 PM<A>
may give some spaceelect
03/27/2019, 4:53 PMlouiscad
03/27/2019, 6:14 PMelect
03/28/2019, 8:11 AMelect
03/28/2019, 2:58 PM