So, I have the following: ``` val type: Class<T...
# announcements
r
So, I have the following:
Copy code
val type: Class<T> = ...
val clazz: Class<Any> = ...
val superClazz = clazz.superclass  // is Class<in Any!>!
// works fine
if (type == clazz) ...
// won't compile: Operator '==' cannot be applied
if (type == superClazz) ...
Why doesn't that work? Doesn't
Class<in Any!>! : Any
still hold true?
r
Class is invariant and you have specified
Class <T>
and I guess (cannot check right now) that == for class has no speciel
out
modifier defined.
Ah no... if you say comparing
Class<T>
against
Class<Any>
works, then there must be an
out
modifier. In this case I guess the
in
modifier contradicts this.
Class<in Any>
<: Any holds but
Class<in Any>
<:
Class<Any>
does not.
now that I have access to Intellij, I am a bit cleverer again,
==
is defined on `Any`and expects an
Any?
. So no
out
modifier required.
but then I have to say I don't get either way == should not be allowed. Looks like a bug to me
The following works, so it must be a bug
Copy code
val a = Any::class.java.superclass
val b: Any? = a
I guess they have implemented some checks to detect unrelated types and got something wrong.
(`if("hello" == 1){}`results in the same error, I think my theory could be correct)