0

I want to write some code for currency stuff, so I try to use € for some nice postfix notation.

But I get this compiler error

Error:(46, 9) illegal character '\u20ac'
def € = EUR
    ^

Am I doing something wrong? Cos $ works fine and is a currency symbol as well.

ziggystar
  • 28,410
  • 9
  • 72
  • 124
Nabil A.
  • 3,270
  • 17
  • 29
  • 1
    `$` is allowed in Scala variable names, while most Unicode characters aren't. Check out this topic: http://stackoverflow.com/questions/7656937/valid-identifier-characters-in-scala – Vadim Landa May 12 '15 at 08:21

1 Answers1

2

Euro symbol is not valid identifier, but you may use it with back-ticks:

scala> def € = 10
 error: illegal character '\u20ac'
   def € = 10
       ^

scala> def `€` = 10
€: Int
Shyamendra Solanki
  • 8,751
  • 2
  • 31
  • 25
  • But if I want to use it as a postfix operator, I have to write 10 '€' what makes this solution not suitable for my case. But in terms of what I asked +1 – Nabil A. May 12 '15 at 12:59