
Using Java Reflection with Kotlin Companion Objects
Handstand Sam handstandsam.com
Aurekai listening
Listen to this summary
Original instrumental score; voice stays in front.
Ready to listen
This reads the text available on this page using your browser's voice. It is not a publisher-recorded narration; voice processing depends on your browser.Kotlin companion objects allow you to add static data and methods associated with a class. This is similar to how Java has static fields and methods. The problem is that Java doesn’t really know what a companion object it, so trying to access one using standard Java reflection might make you go crazy.
The decompiled Java class (created by the Kotlin Compiler) results in this:
More ways to use this
Open on another device
Scan to open this page. Your saved notes and account access are not included.