News for hackers. Stuff that matters.
Re:My last name makes me invisible to Computers (2015) by ajuc on Friday August 18, 2017 @01:01PM (#15047853)
It doesn't have to. null.toString() throws NPE as it should. I would expect "foo" + null to throw NPE as well.

BTW there's another "fun" gotcha, when you interface java code and oracle database which consider empty string and null to be the same thing. Depending on how you handle data from database you end up with null, "", or "null" :)

Re:My last name makes me invisible to Computers (2015) by Asooka on Friday August 18, 2017 @05:46PM (#15050010)
String.valueOf(null) returns "null" though, and that is what "foo" + null uses. I can understand why it would be surprising if you thought it used .toString, but it's clearly listed in the standard.
Re:My last name makes me invisible to Computers (2015) by LukeShu on Friday August 18, 2017 @11:57PM (#15051577)
Sure, but .toString() can be used to change how your class stringifies, so clearly it is being called at some point (perhaps by String.valueOf()).

And indeed,

    public static String valueOf(Object obj) {
        return (obj == null) ? "null" : obj.toString();
    }
http://hg.openjdk.java.net/jdk8/jdk8/jdk/file/687fd7c7986d/s...
Re:My last name makes me invisible to Computers (2015) by incongruity on Friday August 18, 2017 @03:46PM (#15049167)
Interesting – I haven't touched Java in years so I'm definitely out of my element with that language, so thank you.