kotlinkotlin-null-safety

Best way to null check in Kotlin?


Should I use double =, or triple =?

if(a === null)  {
//do something
}

or

if(a == null)  {
//do something
}

Similarly for 'not equals':

if(a !== null)  {
//do something
}

or

if(a != null)  {
//do something
}

Solution

  • Both approaches generate the same bytecode so you can choose whatever you prefer.