gpt4 book ai didi

java - 如何从 JNI 中的类中提取枚举?

转载 作者:塔克拉玛干 更新时间:2023-11-02 18:59:12 24 4
gpt4 key购买 nike

我有一个传递给 native 方法的类,如下所示

public enum Color{  
eRED,
eGREEN,
eBLUE};

public class ConfigColor{
public ColorE color;
public int value;};

public native int HelloWord(ConfigColor ConfigColorcls);

ConfigColor clsConfigColor = new ConfigColor();
clsConfigColor .color = eGREEN;
clsConfigColor . value = 255;

HelloWord(clsConfigColor);

我可以使用 GetIntField 和 GetObjectClass 提取 int 值。但是如何提取ColorE颜色呢?请帮忙

最佳答案

要获取值,您可以使用以下

public static Color getFromInt(int id) {
for (Color candidate : Color.values()) {
if (candidate.getAsInt() == id) {
return candidate;
}
}
throw new RuntimeException("no Color " + id);
}

关于java - 如何从 JNI 中的类中提取枚举?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9175806/

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