(class C).isInstanceOf[Class] where type Class (which is a meta type) contains all classes
(object O).isInstanceOf[?] #where ?.isInstanceOf[Class]
This does not make any sense.
First, class C is a declaration of a new class, you can not call isInstanceOf (nor any other thing) in it, it is not a value. (Something similar applies to object O).
Second, your meta class is Any, if you are referring to the superclass of all classes.
Third, if ? is a value (given you said ?.isInstanceOf[Class]) then you can not said x.isInstanceOf[?], you can not ask if a value is an instance of another value, you can only check if a value is an instance of a class. And that is a runtime check.
InstanceOf relationships aren’t transitive.
It depends on what you mean with transitive. Given that the left operand of isInstanceOf is a value and the right one is a class. You can not really create a transitive relationship (in the formal sense of the word). But, you can check this:
trait A extends Any
trait B extends A
object C extends B
C.isInstanceOf[B] // true
(new B {}).isInstanceOf[A] // true
C.isInstanceOf[A] // true
C,isInstanceOf[Any] // true
And any other check that you want to perform will be true, as long as the right side is a superclass of the value in the left.
And this applies to everything in general, not just to objects. For example:
5.isInstanceOf[Int] // true.
5.isInstanceOf[Any] // true.
So if one states an object is a Class, then (object O) isInstanceOf[Class] and O can’t be passed to Object for instance, because Object is also an instance of Class, so O can’t be an instance of Object because O is at the same level as Object.
Sorry but, I simply do not understand what do you meant here.
I do understand you from the point of a singleton type, but a singleton type is also a type, so O can’t be a singleton type, otherwise it would be excluded as value?
Personally, I have the feeling that (object O) implies that there is an binding in the value layer with name O and also in the class/type layer with the same name. And the singleton type refers to O in the type/class layer, while the value being passed refers to the name in the value layer.
When you do object B extends A, you are:
- Creating a class
B$ that extends the class A.
- Creating a type
B.type that is a subtype of the type A.
- Creating a value
B which is an instance of B$ and of type B.type.
All these three exists in different moments and namespaces.
types only exist in compiletime & classes only exist in the JVM runtime.
That is not so much different that a normal class.
For example when you do class B extends A and then val b = new B. You are:
- Creating a class
B that extends the class A.
- Creating a type
B. that is a subtype of the type A.
- Creating a value
b which is an instance of B and of type B.
As you can see, there are only some naming differences, due the implementation internal details.
But that is all, an object is just a singleton.
Anyways, if you still have questions. I think it would be better if you move the discussion to gitter. There you will get a more interactive experience, and there are many more people that may help you.