I am having difficultie while validating a long variable if it is null. The Code which I am using is :
long late_in= latein_hours.getTime();
It will show an error that java null pointer exception. So how can I validate if it is null then make it equal to zero.
Thanks
long late_in = 0;
if(latein_hours!=null){
late_in= latein_hours.getTime();
}
Primitive can't be null, only reference to object can hold null
value
A long
can’t be null
: if you don't set a value, is automatically set to 0.
If you want a variable that can be null (for example if not initialized), you must use Long
(look the case).
Long
is like a container for long
that can be null
.
Long latein_hours;
long late_in;
if(latein_hours!=null){
late_in= latein_hours.getTime();
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With