kotlin bug?
# announcements
c
kotlin bug?
b
If I remember it right,
someVariable::class.java
is the same as javas
someVariable.getClass()
. So it does not resolve the type during compile time but at runtime depending on the value. Because of that
someVariable
must not be null. If you want to resolve the type statically you could use
GeneratedMessage::class
e
That's not an issue.
those
should've been smartcasted to non-nullable
c
if i use
this
hint is the same, this is just workaround
e
Well, I'm not really sure what is exactly the problem, probably it's for the sake of Java compatibility, because you may accidentally push a null and Kotlin will treat nullable type as a normal type or something. The solution for type resolution is as @Burkhard suggested, resolve the type statically, but it'll bring overheads of reifing type parameter.
c
looks like i don't understand, what exactly should i do?
e
Instead of
this::class.java.name
use
GeneratedMessage::class.java.name
n
Just use
!!
as suggested by the IDE.
Apparently it cannot be smartcasted, which is a bummer, but then it’s safe to use
!!
.
What happens BTW if you just write:
val those = this
?
e
@nestserau where would you put
!!
?
u
n
@Egor Trutenko
those!!::class.java.name
But from the link above I see that it won’t help either.