robstoll
12/14/2019, 6:45 PMfun foo(i: Int): String = ...
fun bar(i: Int): String by foo // does not work, is there another syntax?
Mark Murphy
12/14/2019, 6:52 PMfun foo(i: Int) = i * i
val bar = ::foo
fun main() {
println(bar(3))
}
This assigns a function reference to bar
, which you can then use as a function.robstoll
12/14/2019, 7:02 PMTim McCormack
12/15/2019, 12:52 AMtynn
12/15/2019, 12:50 PMfun bar(i: Int) = foo(i)
?robstoll
12/15/2019, 2:00 PMis it possible to somehow delegate to the other without the need to specify the arguments?
Tim McCormack
12/15/2019, 2:10 PMval bar = ::foo
work for you?Tim McCormack
12/15/2019, 2:11 PMbar
the same function as foo
.robstoll
12/15/2019, 2:19 PMinterface A{
fun bar(i: Int)
}
class B: A{
fun foo(i: Int) = TODO()
override val bar = ::foo // does not override something
}
Tim McCormack
12/15/2019, 2:31 PM