Can I escape braces in a java MessageFormat?

Steve Bosman picture Steve Bosman · Jul 27, 2009 · Viewed 35.6k times · Source

I want to output some braces in a java MessageFormat. For example I know the following does not work:

MessageFormat.format("  public {0} get{1}() {return {2};}\n\n", type, upperCamel, lowerCamel);

Is there a way of escaping the braces surrounding "return {2}"?

Answer

Brian Agnew picture Brian Agnew · Jul 27, 2009

You can put them inside single quotes e.g.

'{'return {2};'}'

See here for more details.