Assume, we have:
class B
class A extends B
trait T
Then it holds:
val a: A with T = new A with T
a.isInstanceOf[B] // result is true !
Is it right to say, the isInstanceOf method checks, if there is at least one type (not all types) which matches the right hand side in a subtype relationship?
At first look, I thought a value with type A with T can not be a subtype of B, because A and T are not both subtypes of B. But it is A or T is a subtype of B — is that right ?
isInstanceOflooks if there is a corresponding entry in the inheritance chain. The chain ofA with TincludesA,BandT, soa.isInstanceOf[B]must be true.edit:
Actually the generated byte code calls javas
instanceof, so it would bea instanceof Bin java. A little more complex call likea.isInstanceOf[A with T]would be(a instanceof A) && (a instanceof T).