Adam S
05/24/2023, 8:29 PM(Kotlin reflection is not available)
?
fun main() {
class Foo
blah(Foo())
}
fun blah(value: Any) {
val cls = value::class
println("cls: $cls")
// cls: class FileKt$main$Foo (Kotlin reflection is not available)
}
Playground demoephemient
05/24/2023, 8:43 PMvalue::class.qualifiedName
Klitos Kyriacou
05/24/2023, 8:47 PMimplementation("org.jetbrains.kotlin:kotlin-reflect:1.8.21")
Adam S
05/24/2023, 8:50 PMqualifiedName
Adam S
05/24/2023, 8:50 PMAdam S
05/24/2023, 8:51 PMcls.java.name
and add class
to the string
println("cls: class ${cls.java.name}")
Ruckus
05/24/2023, 9:21 PMvalue::class.java
, you can do value.javaClass
ephemient
05/25/2023, 12:48 AMsimpleName
might work there but that is a local class so most names don't workephemient
05/25/2023, 12:48 AMjavaClass
was supposed to be deprecated, not sure what happened with that… https://blog.jetbrains.com/kotlin/2017/02/kotlin-1-1-release-candidate-is-here/Youssef Shoaib [MOD]
05/25/2023, 6:32 AMephemient
05/25/2023, 6:35 AMYoussef Shoaib [MOD]
05/25/2023, 7:02 AM.javaClass
extension property, and the 1.1 RC article came out on Feb 17th, merely a week after. Then, on Feb 22nd, this PR undid the deprecation, citing:
its replacement is often inconvenient.1.1.0 was then released on March 1st, 2017. I can't seem to find an issue related to these deprecations though, or a concrete discussion that caused the deprecation to not occur.
Youssef Shoaib [MOD]
05/25/2023, 7:15 AMephemient
05/25/2023, 8:21 AM