Can a case Scala be used in case of a match

Can a case Scala be used in case of a match?

eg. this does not work:

abstract class A case object B extends A object something { val b = B b match { case _:B => println("success") } } not found: type B b match { case _:B => println("success") } ^ 
+5
source share
2 answers

Oh, it looks like this is also compiling:

 abstract class A case object B extends A object something { val b = B b match { case B => println("success") } } 

Scala Fiddle: You can use the case Scala object if matched

+4
source

You need to specify B.type :

 object something { val b = B b match { case _:B.type => println("success") } } 
+8
source

Source: https://habr.com/ru/post/1204218/


All Articles