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 execution 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? (Octal and hex escapes are also considered dull
)
\{ \} is not working, alas…
Tags: JavaFX
January 14, 2008 at 17:04
You only need to escape the { not the }
Use the backslash \ to escape. You can also escape embedded double quotes with a \
Thanks,
Jim Weaver
Helping You Become a “JavaFXpert” Weblog:
http://javafxpert.com
January 14, 2008 at 18:01
Thanky, Jim!
Shame on me, I tried to escape them both, and I got something like
Error in file:/home/alex/NetBeansProjects/L2/src/l2/Main.fx:27: “file:/home/alex/NetBeansProjects/L2/src/l2/Main.fx”: Lexical error at line 27, column 31. Encountered: “}” (125), after : “\\”
The message is pretty clear I should understand that only \} is prohibited.
Thanks a lot!
As a guru you may be interesting in the following construct:
System.out.println("{ "{ "{100}" }" }");which produces 100.
The idea of this: enclose into string concatenation another construction that is concatenation it self…
System.out.println("1 level\{{ "2 level\{{ "3 level has value = {100}" }}" }}");which produces:
1 level{2 level{3 level has value = 100}}
Alas the latest NetBeans plugin is not capable to render it with nice highlighting
January 14, 2008 at 18:08
However ability to escape closing bracket would be very helpful…
say in Java in “” you should not generally escape ‘ but you could if you like, and vice versa in ” you may choose to escape ” or not.
so
case ‘\”‘:
case ‘\”:
// handle quotes
looks much better than
case ‘”‘:
case ‘\”:
// handle quotes
That is why I would have \} escape sequence…