gpt4 book ai didi

java - C++/JNI - 如何访问在 JAVA (Android NDK) 中的 .h 中声明的枚举

转载 作者:太空狗 更新时间:2023-10-29 23:01:08 26 4
gpt4 key购买 nike

我在 C++ 中有头文件,其中声明了一些枚举。

// enum.h
enum event {
event_1,
event_2,
event_3,
event_4
}

C++ 文件和头文件在库 .so 中编译(使用 GNU)。

现在我想在我的 Java 类中这样做:

// Test.java
public class Test {
private event currentEvent;

public test() {
if (currentEvent == event.event_1)
; // I will do my stuff
}
}

有人有建议吗?

谢谢

最佳答案

我怀疑是否有直接的方法来做到这一点。

对于 C 或 C++,您可以使用 SWIG .它自动为 C++ 类和元素生成 Java 包装器。

21.3.5.5 Simple enums

This approach is similar to the type unsafe approach. Each enum item is also wrapped as a static final integer. However, these integers are not generated into a class named after the C/C++ enum. Instead, global enums are generated into the constants interface. Also, enums defined in a C++ class have their enum items generated directly into the Java proxy class rather than an inner class within the Java proxy class. In fact, this approach is effectively wrapping the enums as if they were anonymous enums and the resulting code is as per anonymous enums. The implementation is in the "enumsimple.swg" file.

Compatibility Note: SWIG-1.3.21 and earlier versions wrapped all enums using this approach. The type unsafe approach is preferable to this one and this simple approach is only included for backwards compatibility with these earlier versions of SWIG.

关于java - C++/JNI - 如何访问在 JAVA (Android NDK) 中的 .h 中声明的枚举,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31703969/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com