Why scala not allowing '$' identifier in case statement?
Posted
by Alex R
on Stack Overflow
See other posts from Stack Overflow
or by Alex R
Published on 2010-04-26T23:53:42Z
Indexed on
2010/04/27
1:23 UTC
Read the original article
Hit count: 385
this works as expected
scala> 3 match { case x:Int => 2*x } res1: Int = 6
why does this fail?
scala> 3 match { case $x:Int => 2*$x } :1: error: '=>' expected but ':' found. 3 match { case $x:Int => 2*$x } ^ scala> 3 match { case `$x`:Int => 2*$x } :1: error: '=>' expected but ':' found. 3 match { case `$x`:Int => 2*$x } ^ scala> 3 match { case `$x` : Int => 2*$x } :1: error: '=>' expected but ':' found. 3 match { case `$x` : Int => 2*$x }
'$' is supposed to be a valid identifier character, as demonstrated here:
scala> var y = 1 y: Int = 1 scala> var $y = 2 $y: Int = 2
Thanks
© Stack Overflow or respective owner