I just was tidying my code a bit and there was this piece:
String saving = getValue();
if(saving != null && saving.equals(\"true\")){
// do someth
This is safe - and as you have seen, a good way of avoiding null pointers.
You mention the use of new
for Strings. Many java static code analysis tools will recommend always using literals over new String("foo");
.
Edit:
If you wanted, you could even just use:
if (Boolean.valueOf(saving)) {
...
}
According to the docs, passing null
will return false
.