defineClass

context(env: JniEnv, autofreeScope: AutofreeScope)
fun defineClass(name: CValuesRef<ByteVar>?, loader: JObject?, classBuf: CPointer<ByteVar>, classBufLen: Int): JClass?(source)

Loads a class from a classBuf of raw class data.

The buffer containing the raw class data is not referenced by the VM after the defineClass call returns, and it may be discarded if desired.

Return

a Java class object or null if an error occurs.

Parameters

name

the name of the class or interface to be defined. May be null, or it must match the name encoded within the class file data. Must be encoded in the null-terminated modified UTF-8. Use String.modifiedUtf8 to get it or if you are sure that your string doesn't have illegal characters you may use optimized String.utf8.

loader

a class loader assigned to the defined class. May be null, indicating the "null class loader" (or "bootstrap class loader").

classBuf

buffer containing the .class file data.

classBufLen

buffer length.

Throws

ClassFormatError

if the class data does not specify a valid class.

ClassCircularityError

if a class or interface is its own superclass or superinterface.

if the system runs out of memory.

SecurityException

if the caller attempts to define a class in the "java" package tree.


context(env: JniEnv, autofreeScope: AutofreeScope)
inline fun defineClass(name: String, loader: JObject?, classBuf: CPointer<ByteVar>, classBufLen: Int): JClass(source)

Alias for defineClass which accepts the class name as a Kotlin String.

Throws instead of returning null if the class cannot be defined.