Before null-safety, we know that if we declare variable like this
int a;
Then a
is pointing to a null object.
But, now with sound null safety, when we declare the non-nullable variable with late keyword like this,
late int b;
Then, what is the value in b
? or in other words, b
is pointing to what ?
2
Answers
The
late
keyword means that you are going to define new value as soon as possible, but you definitely will, so if you won’t set any value to and use it, it will through an exception like this:So it does not mean that
b
is null when you use it, it means that although it is null now it will get value very soon before you useb
.please check here
late
keyword is used initialise soon. so you need check that data is null or not. if it’s null means you should initialise or assign