dimanche 29 janvier 2017

scala pattern matching with variable in case clause

I want to do a pattern matching with scala but I have the problem that I want to know if the object is the same type as a variable.

I have this:

user.role match {
  case this.role.getClass => true //here says stable identifier required, but this.role.getClass found
  case _: Role_Admin => true
  case _ => false
}

I understand the problem here, but I need to match it with the variable stored in the instance. Is there any way to do that? Or does anyone know any other good way to do that?

Thank you!

Aucun commentaire:

Enregistrer un commentaire