Getting hung up on an apparently simple problem, for which there is plenty of information (too much to sift through to know what on earth the current status is).
At any rate, here goes.
trait _Foo
class Foo Extends _Foo with WhoAmI
trait WhoAmI {
def who = {
getClass match {
case x: _Foo => "should be Foo instance, which extends _Foo"
case _ => "why?"
}
}
}
val foo = new Foo
foo.who
have tried a guard with classOf and isAssignableFrom, as well as looping through x.getInterfaces (I do at least see _Foo there), but no luck in terms of a direct “lean” match.
Is this erasure “at work” or am I missing an obvious 1-liner?
If this is a duplicate of many other threads, we can close, but please point me in the right direction! 😉
Thanks
You should use
thisinstead ofgetClass:Currently you are calling
getClass(which returns object ofClass[T]type) – for sure thejava.lang.Classclass does not extend your_Footrait – that’s “why?“