kotlin.jvm.javaClass extension used as a callable reference.
Using ::javaClass syntax does not result in a Class<T> instance,
as someone might expect.
Instead, it creates a property reference of type KProperty0<Class<T>>,
which is almost never correct and can lead to unexpected behavior and hard-to-detect bugs.
Provides a fix to use a direct .javaClass call or ::class.java syntax instead.
Example 1: Expression receiver
When ::javaClass is used on an expression, the quick-fix replaces it with a regular .javaClass call:
fun test(a: String) {
val classRef = a::javaClass // KProperty0<Class<String>>
println(classRef) // Prints "property javaClass", not "class java.lang.String"
}
After the quick-fix is applied:
fun test(a: String) {
val classRef = a.javaClass // Class<String>
println(classRef) // Prints "java.lang.String"
}
Example 2: Type receiver
When ::javaClass is used on a type, the quick-fix replaces it with ::class.java:
fun test() {
val classRef = String::javaClass // KProperty1<String, Class<String>>
println(classRef) // Prints "property javaClass", not "class java.lang.String"
}
After the quick-fix is applied:
fun test() {
val classRef = String::class.java // Class<Any>
println(classRef) // Prints "class java.lang.String"
}