Get the object at position `i`, throws an exception if out-of-bounds
(&self, env: &mut JNIEnv<'a>, i: i32)
| 70 | |
| 71 | /// Get the object at position `i`, throws an exception if out-of-bounds |
| 72 | pub fn get(&self, env: &mut JNIEnv<'a>, i: i32) -> Result<T> { |
| 73 | let v = env.call_method( |
| 74 | &self.obj, |
| 75 | "get", |
| 76 | "(I)Ljava/lang/Object;", |
| 77 | &[JValueGen::Int(i)], |
| 78 | )?; |
| 79 | // `.get()` throws on index out of bounds |
| 80 | if env.exception_check()? { |
| 81 | Err(Box::new(InternalJNIError::IndexOutOfBounds { |
| 82 | len: self.size, |
| 83 | idx: i, |
| 84 | })) |
| 85 | } else { |
| 86 | T::cast(env, get_object_ref(v)?) |
| 87 | } |
| 88 | } |
| 89 | |
| 90 | /// Iterate over the elements in the list |
| 91 | pub fn iter(&self, env: &mut JNIEnv<'a>) -> Result<impl Iterator<Item = T>> { |