Scala's match/case for Option[classOf[...]] -
i need check returned type method invoke different methods. code:
class x ... class y ... ... def gettype(input:string) : option[class[_]] = { if ... return some(classof[x]) if ... return some(classof[y]) ... } gettype(input) match { case some(classof[x]) => ... // error case some(classof[y]) => ... case none => ... }
however, got errors:
what might wrong?
i think can't use classof
inside structural match. instead can add condition checks that.
val opt: option[class[_]] = some(classof[int]) opt match { case some(c) if c == classof[string] => "string" case some(c) if c == classof[int] => "int" case none => "no class" case _ => "some other class" } //yields int
Comments
Post a Comment