Fudge
12/03/2019, 12:19 AMclass Foo(val callback: (() -> Unit)? = null) {
init {
if (callback != null) {
callback() // Error: Reference has a nullable type '(() -> Unit)?'
}
}
}
This works fine:
class Foo(callback: (() -> Unit)? = null) {
init {
if (callback != null) {
callback() // Error: Reference has a nullable type '(() -> Unit)?'
}
}
}
And this too:
class Foo(val callback: (() -> Unit)? = null) {
init {
if (callback != null) {
callback.invoke()
}
}
}
streetsofboston
12/03/2019, 1:52 AMval
, cannot be changed after being set
Smart cast should be able to figure that out, and it does in the 3rd example.E.Kisaragi
12/03/2019, 3:13 AMAlexey Belkov [JB]
12/03/2019, 11:40 AMinvoke
callFudge
12/03/2019, 12:47 PM