Tomaz Kragelj
11/10/2017, 10:00 AMvar onDownloadCompleted: ((data: ByteArray) -> Unit)? = null
Coming from Swift, I tried calling it using ? mark but it yields compiler error “(Error:(108, 26) Unexpected tokens (use ‘;’ to separate expressions on the same line)“:
onDownloadCompleted?(bytes)
So currently I’m using longer form which works:
if (onDownloadCompleted != null) {
onDownloadCompleted!!(bytes)
}
But it feels so un-DRY for such a simple task, is there a simpler way? Or am I thinking in wrong direction and should use different callback approach?everald
11/10/2017, 10:08 AMinvoke
eg. onDownloadCompleted?.invoke(bytes)
Tomaz Kragelj
11/10/2017, 10:32 AMmarstran
11/10/2017, 11:39 AM!!
when you do the null-check btw. The variable gets smart casted to the non-nullable type.kirillrakhman
11/10/2017, 12:05 PMvar
propertymarstran
11/10/2017, 12:06 PMradityagumay
11/10/2017, 1:31 PMmarstran
11/10/2017, 1:33 PMinvoke
is the whole point with the answer. You can't do onDownloadCompleted?(bytes)
.radityagumay
11/10/2017, 1:34 PM