Skip to main content

How to escape curly brackets (braces) in JavaFX?

2 replies [Last post]
Joined: 2003-06-24

well I need to write something like:

    System.out.println("NewClass{} is just a way to call NewClass constructor");

of course it fails to compile because it expects some code in the curly brackets, then it would execute it and replace curly bracketed code with this code result. How to avoid it?
I found one way to escape it:
    System.out.println("NewClass\u007B\u007D is just a way to call NewClass constructor");

However it looks pretty dull (as if I tried to embed some Unicode charter which does not fit current encoding or hard to find on keyboard :) )
May be there is a better way to escape?
\{ \} is not working, alas...

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Joined: 2003-06-24

Thanks, my mistake was in trying to escape closing bracket... :(

Joined: 2007-05-18

You only need to escape the { character, not the }. Escape it with a backslash, as in \{

You can also escape an embedded " character with a backslash.

Jim Weaver
Helping You Become a "JavaFXpert" Weblog: