Since myObject.toString()
fails when myObject
is null
(throws a NullPointerException
), it is safer to do myObject+""
, since it's essentially doing String.valueOf(myObject).concat("")
, which doesn't fail, but would instead result in the String "null"
.
However, is this a good practice? My first thought is that it seems like it might take longer to perform, since it's implicitly calling two methods, but it does help guarantee software that doesn't crash.