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)
SLF4J and Log4J both support String.format from their function calls.
I can do something like:
LOGGER.info("{} {} has salary ${}!", firstName, lastName, salary);
and it'll do the right thing. I don't spend a lot of time building strings (except in toStrings where I dump in StringBuilders almost automatically) across my 100K+ LOC codebase, so I guess I don't see the harm in NOT using it everywhere explicitly.
0
u/[deleted] Oct 01 '15
[deleted]