Loading a class with the loadClass method causes the loaded class to have a ClassGraph specific class loader which has still a reference to the ScanResult object returned by the scan() method.
Trying to access an inner, non Java default, property of the loaded classes outside the use{...} block causes in Kotlin an error like "The scan result cannot be access after it has been closed".
Example:
// given
enum class MyEnum { SOMETHING }
interface MyInterface {
val myEnum: MyEnum
}
class MyClass : MyInterface {
override val myEnum: MyEnum
get() = SOMETHING
}
val myList = mutableListOf<MyInterface>()
ClassGraph()...config...scan().use {
it.getClassesImplementing(MyInterface::class.java.canonicalName).forEach {
myList.add(it.loadClass(MyInterface::class.java))
}
}
// then, outside the use block (given that there is an element)
print(myList[0].myEnum)
I would expect that once loaded the class is completely unbound from ClassGraph and the ScanResult
Loading a class with the
loadClassmethod causes the loaded class to have a ClassGraph specific class loader which has still a reference to theScanResultobject returned by thescan()method.Trying to access an inner, non Java default, property of the loaded classes outside the
use{...}block causes in Kotlin an error like "The scan result cannot be access after it has been closed".Example:
I would expect that once loaded the class is completely unbound from ClassGraph and the ScanResult