Skip to main content
10 events
when toggle format what by license comment
Jul 12, 2014 at 9:21 comment added BartoszKP @GregHewgill Thanks for your explanation. Still don't agree with you though :-) The println is obvious - it will print, and the exact mechanism that will lead to correctly printing an int or a string is irrelevant. But that's strongly subjective I think.
Jul 12, 2014 at 0:40 comment added Greg Hewgill @BartoszKP: Code should be obviously correct. If I have to read it twice (and I have some experience with Java) because of two subtle interacting features of the language, then perhaps it could be written another way that is more obviously correct. That is what the point of my review was.
Jul 11, 2014 at 15:57 comment added Simon Forsberg The reason for why String s = ( ... doesn't compile is that it is specified to be a string. If it would be Object obj = ( ... then it would work perfectly fine, and is actually what Java does right now as it make the code call System.out.println(Object) for both the strings and the int.
Jul 11, 2014 at 15:21 comment added Voo To nitpick: The correct translation of Object o = someInt is Object o = Integer.valueOf(someInt). That's more efficient (arguable these days but let's just say so) for small integers and otherwise degrades to new Integer() anyhow. You generally shouldn't call the integer constructor yourself.
Jul 11, 2014 at 15:11 comment added BartoszKP Sorry, I don't get this "review". The whole point of it, is that you don't understand the code posted, because you were not aware of some quite commonly known Java mechanisms? Even if they are not known, the code is readable and works without any surprises. So - what is the point of this review? (disclaimer: I'm asking seriously, but don't mean to be rude - sorry if this comment sounds too offensive - it's not my intention).
Jul 11, 2014 at 2:16 history edited Greg Hewgill CC BY-SA 3.0
deleted 5 characters in body
Jul 11, 2014 at 2:14 comment added rolfl Really small nit-pick: "...an overload that takes an Object parameter (and then calls the toString() method to get a string representation of the object)." This is not strictly accurate. It does not call the object.toString() method. It actually does String.valueOf(object), which has slightly different handling of null object values...
Jul 11, 2014 at 0:57 comment added Greg Hewgill Yes, that's correct. The compiler would choose a separate overload of println() for each type that you pass it.
Jul 11, 2014 at 0:56 comment added Jamal This would (mostly) apply to the ternary operator, right? If I were to have done this with separate println()s using ifs, would it have been proper?
Jul 11, 2014 at 0:50 history answered Greg Hewgill CC BY-SA 3.0