Represents a bridge to interact with Java objects from JavaScript/TypeScript.
The JavaObject class provides static and instance methods to create, manipulate,
and release Java objects via a reflection interface, typically exposed by a
global context (e.g., wx:reflect module). It supports calling methods, accessing
fields, and creating Java proxies with JavaScript handlers.
Usage
Instantiate with a Java class name and constructor arguments to create a new Java object.
Use call to invoke Java methods, get and set to access fields.
Use static methods for advanced operations or to create proxies.
Static Members
reflect: The reflection interface for Java interop.
proxyHandlers: Internal map for proxy handler functions.
nextProxyId: Counter for generating unique proxy handler IDs.
Instance Members
classId: The Java class identifier.
objId: The Java object identifier.
Methods
constructor(className, args): Creates a new Java object.
call(method, args): Calls a Java method.
get(field): Gets a Java field value.
set(field, value): Sets a Java field value.
release(): Releases the Java object.
Static Methods
getClass(name): Gets a Java class ID.
newInstance(classId, args): Creates a new Java object instance.
callMethod(objId, method, args): Calls a method on a Java object.
getField(objId, field): Gets a field value from a Java object.
setField(objId, field, value): Sets a field value on a Java object.
release(objId): Releases a Java object.
fromObjId(objId): Creates a JavaObject from an existing object ID.
createProxy(interfaceName, handler): Creates a Java proxy object with a JavaScript handler.
Throws
If the required global context or reflection module is not available.
Represents a bridge to interact with Java objects from JavaScript/TypeScript.
The
JavaObject
class provides static and instance methods to create, manipulate, and release Java objects via a reflection interface, typically exposed by a global context (e.g.,wx:reflect
module). It supports calling methods, accessing fields, and creating Java proxies with JavaScript handlers.Usage
call
to invoke Java methods,get
andset
to access fields.Static Members
reflect
: The reflection interface for Java interop.proxyHandlers
: Internal map for proxy handler functions.nextProxyId
: Counter for generating unique proxy handler IDs.Instance Members
classId
: The Java class identifier.objId
: The Java object identifier.Methods
constructor(className, args)
: Creates a new Java object.call(method, args)
: Calls a Java method.get(field)
: Gets a Java field value.set(field, value)
: Sets a Java field value.release()
: Releases the Java object.Static Methods
getClass(name)
: Gets a Java class ID.newInstance(classId, args)
: Creates a new Java object instance.callMethod(objId, method, args)
: Calls a method on a Java object.getField(objId, field)
: Gets a field value from a Java object.setField(objId, field, value)
: Sets a field value on a Java object.release(objId)
: Releases a Java object.fromObjId(objId)
: Creates aJavaObject
from an existing object ID.createProxy(interfaceName, handler)
: Creates a Java proxy object with a JavaScript handler.Throws
If the required global context or reflection module is not available.
Throws
For invalid arguments in methods.