June 2018
Intermediate to advanced
310 pages
6h 32m
English
Previously it was noted that Kotin likes variables to be assigned only once. And it also doesn't like nulls so much. You probably wondered how that would ever work out in the real world. In Java, constructs such as this are quite common:
public String getUnixSocketPolling(boolean isBsd) { String value = null; if (isBsd) { value = "kqueue"; } else { value = "epoll"; } return value;}
Of course, this is an oversimplified situation, but still, you have a variable that at some point absolutely must be null, right?
In Java, if is just a statement and doesn't return anything. On the contrary, in Kotlin, if is an expression, meaning it returns a value:
fun getUnixSocketPolling(isBsd : Boolean) : String { val value = if (isBsd) ...Read now
Unlock full access