Does Java have a "@" to avoid string quotes?

There are double quotes in my line, in C# I would do:

 string blah = @"this is my ""text"; 

how can i do this in java?

+9
java string c # quotes double-quotes
Jan 07 '10 at 6:11
source share
2 answers

No. This feature is not available in Java.
From the Sun docs :

When an escape sequence is encountered in a print statement, the compiler interprets it accordingly. For example, if you want to put quotation marks in quotation marks, you must use the escape sequence, \ ", in inner quotation marks. To print a sentence

  She said "Hello!"  to me. 

you write

 System.out.println("She said \"Hello!\" to me."); 
+12
Jan 07 '10 at 6:18
source share

There is currently nothing of the kind, but this is a β€œfixed” request for improvement.

If added, this function will allow such string literals:

 String qry = @" SELECT a.name, b.number FROM User a, Data b WHERE a.name = "James" AND a.id = b.id "; 

Some of the comments deny this mainly by the fact that it is syntactic sugar, but obviously there is a high demand for it, so it is possible that we will see it someday.

+3
Apr 21 2018-10-21T00:
source share



All Articles