by ElliotH · 15y ago · 0 comments
int i = 4;
i.toString(); //Exception - int isn't a class, so i isn't an object, so you can't call its methods.
Integer j = 4;
j.toString(); //Returns "4" as a string, because Integer is a class.
Java would 'encourage' the latter practice at times because its useful to be able to call methods off of characters and integers and such, but there is a difference.Instead you might see:
logger.fatal( String.format("Program crashed on index %d: %s", i, message) );
I think C has a similar construct, not quite as verbose, that would save 7 characters out of the line...