r
Nobody?
k
Does
println(clazz.simpleName == null)
give you the expected result?
s
Do you mean a java anonymous class or a kotlin object ?
If the latter then
::class.objectInstance != null
should work
e
Basically, no, Kotlin does not operate with "anonymous class" definition as Java does, KClass even has no methods to check it. Instead, as was mentioned above, you can check whether the class is anonymous by
clazz.getCanonicalName() == null
, because
Class
of Java has no name for anonymous classes.
r
@spand I don't have access to
KClass
, so
::class.objectInstance!=null
does not work, or do you mean calling that on a Class?
s
What do you have access to ?
r
Just the Class
@kevinmost
println(clazz.simpleName == null)
is false
println(clazz.simpleName)
outputs
main$clazz$1
s
The java
Class
object?
r
japp
the java Class object
basically
val clazz = object: A{}::class.java
s
clazz.kotlin.objectInstance != null
r
just that
clazz
is passed in as parameter
oh interesting,
clazz.kotlin.objectInstance != null
works, thanks, wasn't aware of that this property exists 🙂
s
🙂
r
oh no, it does not work 😞 It only works for named objects like
object B : A
s
Smells like a bug to me. Created an issue for it: https://youtrack.jetbrains.com/issue/KT-22951
👍 1