Description
This is a note found in bind_java_type documentation (https://github.com/jni-rs/jni-rs/blob/master/crates/jni/docs/macros/bind_java_type_1_properties.md#is_instance_of):
The generated as_*() methods perform a runtime IsInstanceOf check.
However, in generated macros, some note like this is automatically generated:
This does not require a runtime type check since any JString is also a ::jni::objects::JCharSequence
Side note
I am adding a get_parcelable_extra method for jni_min_helper::Intent, and I have to avoid #764; the workaround that I tried is to have private IntentApi32 and IntentApi33 bindings that also maps to android.content.Intent, and have this in the original Intent binding in order to avoid runtime class type checking:
is_instance_of = {
api_32 = IntentApi32,
api_33 = IntentApi33,
}
Soon I found this is problematic because it exposes as_api_32 and as_api_33 to the public API, it's just because Intent has been made public. Honestly, I don't know if this should be fixed, because the fix of not exposing generated methods with signature that contains private type seems to be complicated.
Why do I need these as_*() methods? Probably because I can't find a safe Env method for doing similar things (casting &JavaType<'_> to &SuperType<'_>) without runtime check. (I understand jni-rs doesn't allow implicit upcast of borrowed references, because methods from the base class and the derived class may have the same name, and that would be confusing.)
So I did this for now (https://docs.rs/jni-min-helper/0.4.1/src/jni_min_helper/receiver.rs.html#141-170):
// Safety: `Intent` and `IntentApi33` both map to `android.content.Intent`.
let intent: Cast<'_, '_, IntentApi33> = unsafe { env.as_cast_unchecked(self) };
Description
This is a note found in
bind_java_typedocumentation (https://github.com/jni-rs/jni-rs/blob/master/crates/jni/docs/macros/bind_java_type_1_properties.md#is_instance_of):However, in generated macros, some note like this is automatically generated:
Side note
I am adding a
get_parcelable_extramethod forjni_min_helper::Intent, and I have to avoid #764; the workaround that I tried is to have privateIntentApi32andIntentApi33bindings that also maps toandroid.content.Intent, and have this in the originalIntentbinding in order to avoid runtime class type checking:Soon I found this is problematic because it exposes
as_api_32andas_api_33to the public API, it's just becauseIntenthas been made public. Honestly, I don't know if this should be fixed, because the fix of not exposing generated methods with signature that contains private type seems to be complicated.Why do I need these
as_*()methods? Probably because I can't find a safeEnvmethod for doing similar things (casting&JavaType<'_>to&SuperType<'_>) without runtime check. (I understandjni-rsdoesn't allow implicit upcast of borrowed references, because methods from the base class and the derived class may have the same name, and that would be confusing.)So I did this for now (https://docs.rs/jni-min-helper/0.4.1/src/jni_min_helper/receiver.rs.html#141-170):