简体   繁体   English

JNA和Java语言关键字

[英]JNA and Java Language Keywords

Is there a way to map method names, member variables, struct data etc. when the member name is a java reserved keyword? 当成员名称是java保留关键字时,有没有办法映射方法名称,成员变量,结构数据等? I am creating a JNA wrapper for a third party C-library, whose sources I am not able to modify. 我正在为第三方C库创建一个JNA包装器,其源代码我无法修改。 A simplified example would be this: 一个简化的例子是:

// C-library
typedef struct {
    const char* name;
} Class;

typedef struct {
    const Class *class
} Context;

So to map this to JNA I have a class 所以要把它映射到JNA我有一个类

public static class Context extends Structure {
    public Pointer class; // <-- compile error, reserved keyword
}

Is there any way around this? 有没有办法解决? I tried looking at JNA sources (I'm using version 3.2.2) but didn't find anything related. 我尝试查看JNA源代码(我使用的是3.2.2版本),但没有发现任何相关内容。

Structure field names are arbitrary, as long as they are unique, properly typed, and in the correct order, the information will be the same. Structure字段名称是任意的,只要它们是唯一的,正确键入的,并且按正确的顺序,信息将是相同的。 I would recommend at least making them similar to the original, though ( class_ or klass will work). 我建议至少让它们与原版相似,但是( class_klass会起作用)。

You can remap function names with a FunctionMapper . 您可以使用FunctionMapper重新映射函数名称。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM