我正在使用 SWIG 为一些 C 代码生成 Java 包装器。此 C 代码具有 SWIG 使用以下 Java 代理类表示的结构。正如我们所看到的,这个类可以被扩展,因为它没有被声明为
final
。如何使用 SWIG 将此类声明为最终类(即 public final class Test
)?
/* ----------------------------------------------------------------------------
* This file was automatically generated by SWIG (http://www.swig.org).
* Version 3.0.12
*
* Do not make changes to this file unless you know what you are doing--modify
* the SWIG interface file instead.
* ----------------------------------------------------------------------------- */
package abc;
public class Test {
private transient long swigCPtr;
protected transient boolean swigCMemOwn;
protected Test(long cPtr, boolean cMemoryOwn) {
swigCMemOwn = cMemoryOwn;
swigCPtr = cPtr;
}
protected static long getCPtr(Test obj) {
return (obj == null) ? 0 : obj.swigCPtr;
}
protected void finalize() {
delete();
}
public synchronized void delete() {
if (swigCPtr != 0) {
if (swigCMemOwn) {
swigCMemOwn = false;
TestJNI.delete_Test(swigCPtr);
}
swigCPtr = 0;
}
}
public Test() {
this(TestJNI.new_Test(), true);
TestJNI.initialize(swigCPtr, this);
}
}
您可以使用 SWIG 类型图来控制它:
%typemap(javaclassmodifiers) struct Test "public final class"
您还可以通过
SWIGTYPE
而不是 struct Test
来为 所有 课程执行此操作。