3
Although the doubt is very basic, I would like to understand why the equals
in this case:
String texto = null;
System.out.println("teste".equals(texto));
Returns false
normally (example in ideone), but in the example below:
String texto = null;
System.out.println(texto.equals(""));
He bursts the exception NullPointerException
, as can also be seen in ideone.
In both cases there is a comparison with null
, but the return is different depending on the side on which the null
is past, why this occurs?
https://en.wikipedia.org/wiki/Yoda_conditions
– utluiz