JObject constructor
Default constructor. Create java object.
args
constructor argument.
Dart basic type not equal as java basic type, such as dart not contain byte, short, long, float.
But the parameter list need same as java method parameter list.
If java method parameter list contain like byte, short, you need use wrapper class is dart.
See float, byte, short, jchar, long.
For example:
Java class:
class Test {
Test(int i, byte b, short s);
}
dart class:
@nativeJavaClass(className: 'com/test/Test')
class Test extend JObject {
Test(int i, int b, int s): super(args: [i, byteb
, shorts
);
}
isInterface
java class if is a interface class.
If java class is specified by className
, we will use it first.
Otherwise we will get className from @nativeJavaClass
annotation's register.
When use native class, please use @nativeJavaClass
annotation first.
Implementation
JObject({List? args, bool isInterface = false, String? className}) {
_cls = className ?? getRegisterJavaClass(runtimeType.toString());
if (_cls == null) {
throw 'Java class name is null, you can specify the java class name in constructor'
' or use @nativeJavaClass annotation to specify the java class';
}
_ptr = newObject(_cls!, this, args: args, isInterface: isInterface);
if (!isInterface) {
bindLifeCycleWithJava(_ptr);
}
}