Abhash Upadhyaya
Abhash Upadhyaya

Reputation: 727

How to use a var from object in match case condition

I have an object with mutable variables which will be populated using a property file. When I'm trying to use these variables in match condition, I'm getting an error stable identifier required, but com.zzz.yyy.xxx.Object.Var.toString found. case SourceTable(Object.Var.toString) => {

I also tried using case class but still getting the same error. I need to read the values from property file only and can't be hard-coded in match condition.

Is there a way to do it?

NOTE: I'm new to scala.

Upvotes: 0

Views: 59

Answers (1)

dveim
dveim

Reputation: 3482

Try case SourceTable(s) if s == Object.Var.toString.

Basically, you cannot use vars (unstable identifier) inside unapply, due to what code that would generate.

Also, https://stackoverflow.com/a/35218246/6345611 (and, particularly, last comment there) might be useful for you.

Upvotes: 1

Related Questions