diff --git a/Doc/Manual/Java.html b/Doc/Manual/Java.html index 85757d1cb..69cdc4eba 100644 --- a/Doc/Manual/Java.html +++ b/Doc/Manual/Java.html @@ -8165,40 +8165,52 @@ public class Container { // Ensure that the GC doesn't collect any Element set from Java // as the underlying C++ class stores a shallow copy private Element elementReference; - private long getCPtrAndAddReference(Element element) { - elementReference = element; - return Element.getCPtr(element); - } public void setElement(Element e) { - exampleJNI.Container_setElement(swigCPtr, this, getCPtrAndAddReference(e), e); + exampleJNI.Container_setElement(swigCPtr, this, Element.getCPtr(e), e); + elementReference = e; } }
-The following typemaps will generate the desired code. -The 'javain' typemap matches the input parameter type for the setElement method. -The 'javacode' typemap simply adds in the specified code into the Java proxy class. +The following typemaps can be used to generate this code:
-%typemap(javain) Element *e "getCPtrAndAddReference($javainput)"
-
%typemap(javacode) Container %{
// Ensure that the GC doesn't collect any element set from Java
// as the underlying C++ class stores a shallow copy
private Element elementReference;
- private long getCPtrAndAddReference(Element element) {
- elementReference = element;
- return Element.getCPtr(element);
- }
%}
+
+%typemap(javain,
+ post=" elementReference = $javainput;"
+ ) Element *e "Element.getCPtr($javainput)"
+The 'javacode' typemap simply adds in the specified code into the Java proxy class. +The 'javain' typemap matches the input parameter type and name for the setElement method and +the 'post' typemap attribute allows adding code after the JNI call. +The 'post' code is generated into a finally block after the JNI call so the resulting code isn't quite +as mentioned earlier, setElement is actually: +
+ +
+ public void setElement(Element e) {
+ try {
+ exampleJNI.Container_setElement(swigCPtr, this, Element.getCPtr(e), e);
+ } finally {
+ elementReference = e;
+ }
+ }
+
+