DEV Community

Discussion on: 5 simple coding tricks to make your application more stable

Collapse
 
juanip42 profile image
Juani

Adding to the comparison topic, when you have to compare two objects and any of them could be null, you can leverage the util method Objects#equals(Object a, Object b). It is available since Java 7 and its implementation is very simple:

return (a == b) || (a != null && a.equals(b));

Collapse
 
pazvanti profile image
pazvanti

Indeed, the Objects.equals() method is really usefull and saved many apps, including mine, from crashes :D