MessageFormat.format()
.
While occasionally intended, this is usually a misuse of the formatting method
and may even cause unexpected exceptions if the variables used in the concatenated string contain
special characters like {
.
Also, sometimes this could be the result
of mistakenly concatenating a string format argument by typing a +
when a ,
was meant.
Example:
String formatGreeting(String userName, int balance) {
return MessageFormat.format("Hello, " + userName + "! Your balance is {0}.", balance);
}
Here, the userName
will be interpreted as a part of the format string, which may result
in IllegalArgumentException
(for example, if userName
is "{"
).
This call should be probably replaced with MessageFormat.format("Hello, {0}! Your balance is {1}.", userName, balance)
.