One problem with .format
is that you lose static type safety. You can have too few arguments for your format, and you can have the wrong types for the format specifiers - both leading to an IllegalFormatException
at runtime, so you might end up with logging code that breaks production.
In contrast, the arguments to +
can be tested by the compiler.
The security history of printf (on which the format
function is modeled) is long and frightening.