mcintyre321
mcintyre321

Reputation: 13306

Why does scala allow single quotes in strings to be escaped?

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

Answers (1)

sepp2k
sepp2k

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

Related Questions