Reputation: 13306
I was just reading a scala tutorial, and it seems that when writing strings, scala treats \'
as '
, but also treats '
as '
val a = "\'" // evaluates to '
val b = "'" // evaluates to '
a == b //true
This doesn't seem like a desirable property of the language* - why is it so?
Upvotes: 2
Views: 3622
Reputation: 370172
By allowing \'
in ""
and \"
in ''
, there is only one set of legal escape sequences for both string and character literals. This way the language designers didn't have to define two separate sets, which would have made the language specification and the implementation (slightly) more complicated.
Upvotes: 5