December 2017
Intermediate to advanced
260 pages
7h 34m
English
In Java, the following code will throw NullPointerException, but it will still perfectly compile. Hence it never comes to our attention that we are coding an issue that can crash the application:
private Button createTweet=null; createTweet.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { } });
And the following code in Kotlin will give a compile-time error:
var createTweet: Button? = null createTweet.setOnClickListener({ // Do button click operation })
That means Kotlin compiler is intelligent enough that it knows that createTweet can be null and until a developer does null checks code should not compile. Seems like it believes the Prevention is better than cure
Read now
Unlock full access