#java #jni #java-class #api-bindings

nightly jni-bind

简化从Java导入类的过程

2个版本

0.1.6 2024年8月6日
0.1.5 2024年8月6日

84FFI

Download history 137/week @ 2024-07-27 521/week @ 2024-08-03 29/week @ 2024-08-10

687 每月下载量

MIT 许可证

33KB
701 代码行

jni-bind-rs

Docs Crates.io Crates.io

简化从Java导入类的过程!

此库提供 import_class 宏,自动实现对象结构。所有方法ID和类都被缓存以提高性能。

已知限制

  • 无法导入泛型类和方法。
  • 无法导入常量。

示例

import_class 的基本用法

#![no_main]

use jni_bind::import_class;
use jni_bind::{jboolean, jint, jlong};

import_class! {
    "java/lang/Object";
    Object;
    constructor();
    /// Indicates whether some other object is "equal to" this one.
    fn equals(&self, other: Object) ->  jboolean;
    /// Returns a hash code value for the object.
    fn hashCode(&self) -> jint;
    /// Wakes up a single thread that is waiting on this object's monitor.
    fn notify(&self) -> ();
    /// Wakes up all threads that are waiting on this object's monitor.
    fn notifyAll(&self) -> ();
    /// Returns a string representation of the object.
    fn toString(&self) -> String;
    /// Causes the current thread to wait until it is awakened,
    /// typically by being notified or interrupted,
    /// or until a certain amount of real time has elapsed.
    fn wait(&self, timeout_millis: jlong, nanos: jint) -> ();
}

import_class!{
    "java/lang/String";
    String;
    extends Object;
}

依赖关系

~2–12MB
~92K SLoC