Java doubt: .Equals ()

2

At work I'm using Java and I have to use the equals () function frequently.

My question is what is the difference between

!"".equals(objeto);

in front of

!objeto.equals("");

At work they force me to use the first, but I do not understand why.

Thank you.

    
asked by DieGNU 09.07.2018 в 13:04
source

1 answer

7

If objeto is null , with the first expression you get true ; in the second expression he throws a NullPointerException .

    
answered by 09.07.2018 в 13:10