https://kotlinlang.org logo
#announcements
Title
# announcements
s

svenjacobs

03/23/2017, 7:32 AM
@moelholm I believe the difference is whether a Java
Class
or a Kotlin
KClass
is expected.
::class.java
will return
Class
.
m

moelholm

03/23/2017, 7:55 AM
Hi Sven. I think you are spot on. But the @RunWith JUnit annotation does indeed expect a Class. When I look in IntelliJ. But I guess that a KClass "is-a" Class when observed from Java... and perhaps that's enough for the JUnit runner framework to work
o

okkero

03/23/2017, 8:08 AM
This is a special case for annotations. A
KClass
does not in general share an is-a relationship with
Class
See quote: "If you need to specify a class as an argument of an annotation, use a Kotlin class (KClass). The Kotlin compiler will automatically convert it to a Java class, so that the Java code will be able to see the annotations and arguments normally." https://kotlinlang.org/docs/reference/annotations.html#constructors
m

moelholm

03/23/2017, 8:14 AM
Awesome, Ole - thanks for the explanation
7 Views