https://kotlinlang.org logo
#reflect
Title
# reflect
g

groostav

03/13/2019, 7:52 PM
Hey guys, regarding extension functions and reflection, is there a generally accepted solution to "search" for extension functions given you only have an instance? What about an instance and a couple package names?
u

udalov

03/14/2019, 10:29 PM
The first is generally impossible by normal means, since the Java reflection API doesn't provide any way to search for all classes available via the class loader. So any solution here would be an enormous hack :) The second is more complicated. Basically it's still impossible for the reason that a package name doesn't identify names of the classes in that package which the Kotlin reflection needs. However, if you'd also give the name of the module, Kotlin reflection would be able to look into the corresponding
.kotlin_module
file (provided that it hasn't been stripped in the build process, the possibility of which is by the way investigated right now by the Android team, see https://youtrack.jetbrains.com/issue/KT-30344), fetch the class names from there and load all the extensions. We've discussed this feature a few years ago but never had the chance to implement it, and there were no external requests AFAIK, so it's still not implemented.
2 Views