Readable Code - Remove Checking null

Readable Code – Checking NULL

We must have come across these lines of code many times

//JAVA
bool func(String name)
{
if ( (name != null) && (name.equals("true") ) {
...
} else {
...
}
}


A better way to code this would be


//JAVA
bool func(String name)
{
if ( "true".equals(name) ) {
...
} else {
...
}
}

Labels: ,


About this entry