And more specific example:
abstract trait A
trait B extends A
trait C extends A
How to check what traits that extend trait A (it can be from 0 to many) were mixed in specified class?
How about a hybrid of the other answers
abstract trait A //interested in this one
trait B extends A //and this one
trait C extends A //this one too
trait D //don't care about this one though
val x = new A with B with D
x.getClass.getInterfaces.filter(classOf[A].isAssignableFrom(_))
returns
Array[java.lang.Class[_]] = Array(interface A, interface B)
scala> val x = new A with B with C
x: java.lang.Object with A with B with C = $anon$1@8ea25fa
scala> x.getClass.getInterfaces
res11: Array[java.lang.Class[_]] = Array(interface A, interface B, interface C)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With