as<T extends JObject> method
Casts this object to another type.
If releaseOriginal is true, the casted object will be released.
Throws CastError if this object is not an instance of type.
Implementation
T as<T extends JObject>(
JType<T> type, {
bool releaseOriginal = false,
}) {
if (!isA(type)) {
throw CastError('not a subtype of "${type.signature}"');
}
if (releaseOriginal) {
final ret =
JObject.fromReference(JGlobalReference(reference.pointer)) as T;
reference.setAsReleased();
return ret;
}
final newRef = JGlobalReference(Jni.env.NewGlobalRef(reference.pointer));
return JObject.fromReference(newRef) as T;
}