5

Possible Duplicate:
Using comparison operators in Scala’s pattern matching system

For below method I receive an error : "'=>' expected but integer literal found."

Is it not possible to check if x is greater than another number and or is there an alternative approach to return "greater than 2" if '> 2' is matched ?

 def describe(x: Any) = x match {
    case 5 => "five"
    case > 2 => "greater than 2"
  }
Community
  • 1
  • 1
user701254
  • 3,935
  • 7
  • 42
  • 53

1 Answers1

10

Try:

def describe(x: Any) = x match {
  case 5 => "five"
  case x: Int if (x > 2) => "greater than 2"
}
Matthew Farwell
  • 60,889
  • 18
  • 128
  • 171