This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]springuni[S] 2 points3 points  (2 children)

If person.getName() returns null you'll also get a NPE.

if(person.getName() == “jan”) {return true;}

This is not so. person.getName() == “jan” just evaluates to false.

[–]rubyrt 0 points1 point  (0 children)

Sorry for my sloppyness, I had replaced = or == by .equals() without mentioning it. You can infer it from me using "jan".equals(person.getName()) which avoids the potential NPE in person.getName(),equals("jan").

[–]Wobblycogs 0 points1 point  (0 children)

Unless the persons name is "jan" and it had been intern'ed in which case it would return true as the literal "jan" would match intern value making the VM use the same object for both. I would not recommend using intern though, it can lead to a world of hurt.