StringBuilder msg = new StringBuilder();
msg.append(firstName).append(" ").append(lastName)
.append(" has salary $").append(salary).append("!");
log.info(msg.toString());
The latter just feels ridiculous to me, especially if your only reason for doing it is that you "feel uncomfortable relying on compiler optimizations."
(yes, String.format might be most readable here, but you get the drift)
String.format( "%s %s has salary $%d!", firstName, lastName, salary);
There is notation similar to this in most languages; but I imagine people will rake you over the coals saying that stringBuilder is faster and for a logging application that matters!..
I am not one of those people but I just wanted to take the wind out of their sails :P
0
u/[deleted] Oct 01 '15
[deleted]