Reputation:
Suppose I've 2 case classes :
case class A (r: String) // with value "rr"
case class B (rr:String) // with value "ask"
how can I match the two so that
if(*value of case class B(A)* == *value of case class B.rr*) true
Is it possible in scala if yes then how?
I tried A.getClass.getName.startsWith(B.rr)
but got no output
Upvotes: 0
Views: 46
Reputation: 4585
If I understand the problem correctly, you want to check whether B.rr
has some given class name as its values (and then the r
member of A
is irrelevant to this). Here is a solution in that case:
val b = new B("A")
b match {
case B(classOf[A].getSimpleName) => // we know b.rr == "A"
case _ => // b.rr != "A"
}
You can also just use if (b.rr == classOf[A].getSimpleName) ... else ...
Upvotes: 1