Reputation: 33
I'm trying to load kotlin.String
using SystemClassLoader
inputClassName = String::class.qualifiedName.toString()
val input = ClassLoader.getSystemClassLoader()
.loadClass(inputClassName) // here I get error
and I'm getting error. Stack trace:
Exception in thread "main" java.lang.ClassNotFoundException: kotlin.String
at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
at java.lang.ClassLoader.loadClass(ClassLoader.java:419)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:352)
at java.lang.ClassLoader.loadClass(ClassLoader.java:352)
at block.execution.Executor.init(Executor.kt:40)
at block.AppKt.main(App.kt:50)
What am I doing wrong? How can I fix it?
Upvotes: 3
Views: 1653
Reputation: 170859
kotlin.String
doesn't exist as a class which can be loaded, it is mapped to java.lang.String
by the compiler. String::class.java.name
will give you the actual name of the class.
Of course, as Mikhail Kopylov points out, there is little point loading a class by name of an already loaded class. Maybe to load it in a specific ClassLoader
, but String
will definitely be loaded by the system class loader anyway.
Upvotes: 4