bind: fix field accessors for Go implemented Java classes

The go_seq_to_refnum function handles its argument object as a Java
object if it doesn't implement Seq.Proxy. Java classes implemented in
Go does not implement Seq.Proxy, but when passing "this" references to
Go, instances must be treated as a Go object.

Use go_seq_to_refnum_go everywhere "this" is passed to Go, which fixes
field accessors and simplifies the method call case.

Change-Id: I3d01c63d7b2081e6344ece431f5e5021a9dd7662
Reviewed-on: https://go-review.googlesource.com/31171
Reviewed-by: David Crawshaw <crawshaw@golang.org>
diff --git a/bind/genjava.go b/bind/genjava.go
index c0856b0..59d2f88 100644
--- a/bind/genjava.go
+++ b/bind/genjava.go
@@ -889,7 +889,7 @@
 	g.Printf("JNIEXPORT void JNICALL\n")
 	g.Printf("Java_%s_%s_set%s(JNIEnv *env, jobject this, %s v) {\n", g.jniPkgName(), o.Name(), f.Name(), g.jniType(f.Type()))
 	g.Indent()
-	g.Printf("int32_t o = go_seq_to_refnum(env, this);\n")
+	g.Printf("int32_t o = go_seq_to_refnum_go(env, this);\n")
 	g.genJavaToC("v", f.Type(), modeRetained)
 	g.Printf("proxy%s_%s_%s_Set(o, _v);\n", g.pkgPrefix, o.Name(), f.Name())
 	g.genRelease("v", f.Type(), modeRetained)
@@ -900,7 +900,7 @@
 	g.Printf("JNIEXPORT %s JNICALL\n", g.jniType(f.Type()))
 	g.Printf("Java_%s_%s_get%s(JNIEnv *env, jobject this) {\n", g.jniPkgName(), o.Name(), f.Name())
 	g.Indent()
-	g.Printf("int32_t o = go_seq_to_refnum(env, this);\n")
+	g.Printf("int32_t o = go_seq_to_refnum_go(env, this);\n")
 	g.Printf("%s r0 = ", g.cgoType(f.Type()))
 	g.Printf("proxy%s_%s_%s_Get(o);\n", g.pkgPrefix, o.Name(), f.Name())
 	g.genCToJava("_r0", "r0", f.Type(), modeRetained)
@@ -996,13 +996,7 @@
 	sig := o.Type().(*types.Signature)
 	res := sig.Results()
 	if sName != "" {
-		if isjava {
-			// We need the Go object backing this GoObject. Use
-			// the _go variant (here only) to get the Go refnum.
-			g.Printf("int32_t o = go_seq_to_refnum_go(env, __this__);\n")
-		} else {
-			g.Printf("int32_t o = go_seq_to_refnum(env, __this__);\n")
-		}
+		g.Printf("int32_t o = go_seq_to_refnum_go(env, __this__);\n")
 	}
 	params := sig.Params()
 	first := 0
diff --git a/bind/java/ClassesTest.java b/bind/java/ClassesTest.java
index 897fa2f..83e66a4 100644
--- a/bind/java/ClassesTest.java
+++ b/bind/java/ClassesTest.java
@@ -71,6 +71,11 @@
 		assertNotNull("RuntimeException", exc);
 	}
 
+	public void testField() {
+		GoRunnable r = new GoRunnable();
+		String f = r.getField();
+	}
+
 	public void testGoObject() {
 		Runnable r = new GoRunnable();
 		r.run();
diff --git a/bind/testdata/classes.java.c.golden b/bind/testdata/classes.java.c.golden
index c8c6a73..fd89a34 100644
--- a/bind/testdata/classes.java.c.golden
+++ b/bind/testdata/classes.java.c.golden
@@ -166,14 +166,14 @@
 
 JNIEXPORT void JNICALL
 Java_go_java_Future_setFuture(JNIEnv *env, jobject this, jobject v) {
-    int32_t o = go_seq_to_refnum(env, this);
+    int32_t o = go_seq_to_refnum_go(env, this);
     int32_t _v = go_seq_to_refnum(env, v);
     proxyjava_Future_Future_Set(o, _v);
 }
 
 JNIEXPORT jobject JNICALL
 Java_go_java_Future_getFuture(JNIEnv *env, jobject this) {
-    int32_t o = go_seq_to_refnum(env, this);
+    int32_t o = go_seq_to_refnum_go(env, this);
     int32_t r0 = proxyjava_Future_Future_Get(o);
     jobject _r0 = go_seq_from_refnum(env, r0, NULL, NULL);
     return _r0;
@@ -197,14 +197,14 @@
 
 JNIEXPORT void JNICALL
 Java_go_java_InputStream_setInputStream(JNIEnv *env, jobject this, jobject v) {
-    int32_t o = go_seq_to_refnum(env, this);
+    int32_t o = go_seq_to_refnum_go(env, this);
     int32_t _v = go_seq_to_refnum(env, v);
     proxyjava_InputStream_InputStream_Set(o, _v);
 }
 
 JNIEXPORT jobject JNICALL
 Java_go_java_InputStream_getInputStream(JNIEnv *env, jobject this) {
-    int32_t o = go_seq_to_refnum(env, this);
+    int32_t o = go_seq_to_refnum_go(env, this);
     int32_t r0 = proxyjava_InputStream_InputStream_Get(o);
     jobject _r0 = go_seq_from_refnum(env, r0, NULL, NULL);
     return _r0;
@@ -218,14 +218,14 @@
 
 JNIEXPORT void JNICALL
 Java_go_java_Object_setObject(JNIEnv *env, jobject this, jobject v) {
-    int32_t o = go_seq_to_refnum(env, this);
+    int32_t o = go_seq_to_refnum_go(env, this);
     int32_t _v = go_seq_to_refnum(env, v);
     proxyjava_Object_Object_Set(o, _v);
 }
 
 JNIEXPORT jobject JNICALL
 Java_go_java_Object_getObject(JNIEnv *env, jobject this) {
-    int32_t o = go_seq_to_refnum(env, this);
+    int32_t o = go_seq_to_refnum_go(env, this);
     int32_t r0 = proxyjava_Object_Object_Get(o);
     jobject _r0 = go_seq_from_refnum(env, r0, NULL, NULL);
     return _r0;
@@ -246,14 +246,14 @@
 
 JNIEXPORT void JNICALL
 Java_go_java_Runnable_setRunnable(JNIEnv *env, jobject this, jobject v) {
-    int32_t o = go_seq_to_refnum(env, this);
+    int32_t o = go_seq_to_refnum_go(env, this);
     int32_t _v = go_seq_to_refnum(env, v);
     proxyjava_Runnable_Runnable_Set(o, _v);
 }
 
 JNIEXPORT jobject JNICALL
 Java_go_java_Runnable_getRunnable(JNIEnv *env, jobject this) {
-    int32_t o = go_seq_to_refnum(env, this);
+    int32_t o = go_seq_to_refnum_go(env, this);
     int32_t r0 = proxyjava_Runnable_Runnable_Get(o);
     jobject _r0 = go_seq_from_refnum(env, r0, NULL, NULL);
     return _r0;
diff --git a/bind/testdata/interfaces.java.c.golden b/bind/testdata/interfaces.java.c.golden
index 1295730..ed6616d 100644
--- a/bind/testdata/interfaces.java.c.golden
+++ b/bind/testdata/interfaces.java.c.golden
@@ -114,7 +114,7 @@
 
 JNIEXPORT void JNICALL
 Java_go_interfaces_Interfaces_00024proxyError_err(JNIEnv* env, jobject __this__) {
-    int32_t o = go_seq_to_refnum(env, __this__);
+    int32_t o = go_seq_to_refnum_go(env, __this__);
     int32_t r0 = proxyinterfaces_Error_Err(o);
     jobject _r0 = go_seq_from_refnum(env, r0, proxy_class__error, proxy_class__error_cons);
     go_seq_maybe_throw_exception(env, _r0);
@@ -132,7 +132,7 @@
 
 JNIEXPORT jint JNICALL
 Java_go_interfaces_Interfaces_00024proxyI_rand(JNIEnv* env, jobject __this__) {
-    int32_t o = go_seq_to_refnum(env, __this__);
+    int32_t o = go_seq_to_refnum_go(env, __this__);
     int32_t r0 = proxyinterfaces_I_Rand(o);
     jint _r0 = (jint)r0;
     return _r0;
@@ -149,7 +149,7 @@
 
 JNIEXPORT void JNICALL
 Java_go_interfaces_Interfaces_00024proxyI1_j(JNIEnv* env, jobject __this__) {
-    int32_t o = go_seq_to_refnum(env, __this__);
+    int32_t o = go_seq_to_refnum_go(env, __this__);
     proxyinterfaces_I1_J(o);
 }
 
@@ -162,7 +162,7 @@
 
 JNIEXPORT void JNICALL
 Java_go_interfaces_Interfaces_00024proxyI2_g(JNIEnv* env, jobject __this__) {
-    int32_t o = go_seq_to_refnum(env, __this__);
+    int32_t o = go_seq_to_refnum_go(env, __this__);
     proxyinterfaces_I2_G(o);
 }
 
@@ -175,7 +175,7 @@
 
 JNIEXPORT jobject JNICALL
 Java_go_interfaces_Interfaces_00024proxyI3_f(JNIEnv* env, jobject __this__) {
-    int32_t o = go_seq_to_refnum(env, __this__);
+    int32_t o = go_seq_to_refnum_go(env, __this__);
     int32_t r0 = proxyinterfaces_I3_F(o);
     jobject _r0 = go_seq_from_refnum(env, r0, proxy_class_interfaces_I1, proxy_class_interfaces_I1_cons);
     return _r0;
@@ -192,7 +192,7 @@
 
 JNIEXPORT void JNICALL
 Java_go_interfaces_Interfaces_00024proxyLargerI_anotherFunc(JNIEnv* env, jobject __this__) {
-    int32_t o = go_seq_to_refnum(env, __this__);
+    int32_t o = go_seq_to_refnum_go(env, __this__);
     proxyinterfaces_LargerI_AnotherFunc(o);
 }
 
@@ -205,7 +205,7 @@
 
 JNIEXPORT jint JNICALL
 Java_go_interfaces_Interfaces_00024proxyLargerI_rand(JNIEnv* env, jobject __this__) {
-    int32_t o = go_seq_to_refnum(env, __this__);
+    int32_t o = go_seq_to_refnum_go(env, __this__);
     int32_t r0 = proxyinterfaces_LargerI_Rand(o);
     jint _r0 = (jint)r0;
     return _r0;
@@ -222,7 +222,7 @@
 
 JNIEXPORT jint JNICALL
 Java_go_interfaces_Interfaces_00024proxySameI_rand(JNIEnv* env, jobject __this__) {
-    int32_t o = go_seq_to_refnum(env, __this__);
+    int32_t o = go_seq_to_refnum_go(env, __this__);
     int32_t r0 = proxyinterfaces_SameI_Rand(o);
     jint _r0 = (jint)r0;
     return _r0;
@@ -239,7 +239,7 @@
 
 JNIEXPORT void JNICALL
 Java_go_interfaces_Interfaces_00024proxyWithParam_hasParam(JNIEnv* env, jobject __this__, jboolean p0) {
-    int32_t o = go_seq_to_refnum(env, __this__);
+    int32_t o = go_seq_to_refnum_go(env, __this__);
     char _p0 = (char)p0;
     proxyinterfaces_WithParam_HasParam(o, _p0);
 }
diff --git a/bind/testdata/issue10788.java.c.golden b/bind/testdata/issue10788.java.c.golden
index 132b42c..24e883c 100644
--- a/bind/testdata/issue10788.java.c.golden
+++ b/bind/testdata/issue10788.java.c.golden
@@ -39,14 +39,14 @@
 
 JNIEXPORT void JNICALL
 Java_go_issue10788_TestStruct_setValue(JNIEnv *env, jobject this, jstring v) {
-    int32_t o = go_seq_to_refnum(env, this);
+    int32_t o = go_seq_to_refnum_go(env, this);
     nstring _v = go_seq_from_java_string(env, v);
     proxyissue10788_TestStruct_Value_Set(o, _v);
 }
 
 JNIEXPORT jstring JNICALL
 Java_go_issue10788_TestStruct_getValue(JNIEnv *env, jobject this) {
-    int32_t o = go_seq_to_refnum(env, this);
+    int32_t o = go_seq_to_refnum_go(env, this);
     nstring r0 = proxyissue10788_TestStruct_Value_Get(o);
     jstring _r0 = go_seq_to_java_string(env, r0);
     return _r0;
@@ -54,7 +54,7 @@
 
 JNIEXPORT void JNICALL
 Java_go_issue10788_Issue10788_00024proxyTestInterface_doSomeWork(JNIEnv* env, jobject __this__, jobject s) {
-    int32_t o = go_seq_to_refnum(env, __this__);
+    int32_t o = go_seq_to_refnum_go(env, __this__);
     int32_t _s = go_seq_to_refnum(env, s);
     proxyissue10788_TestInterface_DoSomeWork(o, _s);
 }
@@ -69,7 +69,7 @@
 
 JNIEXPORT void JNICALL
 Java_go_issue10788_Issue10788_00024proxyTestInterface_multipleUnnamedParams(JNIEnv* env, jobject __this__, jlong p0, jstring p1, jlong p2) {
-    int32_t o = go_seq_to_refnum(env, __this__);
+    int32_t o = go_seq_to_refnum_go(env, __this__);
     nint _p0 = (nint)p0;
     nstring _p1 = go_seq_from_java_string(env, p1);
     int64_t _p2 = (int64_t)p2;
diff --git a/bind/testdata/issue12328.java.c.golden b/bind/testdata/issue12328.java.c.golden
index 09e5223..da995de 100644
--- a/bind/testdata/issue12328.java.c.golden
+++ b/bind/testdata/issue12328.java.c.golden
@@ -28,14 +28,14 @@
 
 JNIEXPORT void JNICALL
 Java_go_issue12328_T_setErr(JNIEnv *env, jobject this, jobject v) {
-    int32_t o = go_seq_to_refnum(env, this);
+    int32_t o = go_seq_to_refnum_go(env, this);
     int32_t _v = go_seq_to_refnum(env, v);
     proxyissue12328_T_Err_Set(o, _v);
 }
 
 JNIEXPORT jobject JNICALL
 Java_go_issue12328_T_getErr(JNIEnv *env, jobject this) {
-    int32_t o = go_seq_to_refnum(env, this);
+    int32_t o = go_seq_to_refnum_go(env, this);
     int32_t r0 = proxyissue12328_T_Err_Get(o);
     jobject _r0 = go_seq_from_refnum(env, r0, proxy_class__error, proxy_class__error_cons);
     return _r0;
diff --git a/bind/testdata/issue12403.java.c.golden b/bind/testdata/issue12403.java.c.golden
index b641ba9..699aa33 100644
--- a/bind/testdata/issue12403.java.c.golden
+++ b/bind/testdata/issue12403.java.c.golden
@@ -28,7 +28,7 @@
 
 JNIEXPORT jstring JNICALL
 Java_go_issue12403_Issue12403_00024proxyParsable_fromJSON(JNIEnv* env, jobject __this__, jstring jstr) {
-    int32_t o = go_seq_to_refnum(env, __this__);
+    int32_t o = go_seq_to_refnum_go(env, __this__);
     nstring _jstr = go_seq_from_java_string(env, jstr);
     nstring r0 = proxyissue12403_Parsable_FromJSON(o, _jstr);
     jstring _r0 = go_seq_to_java_string(env, r0);
@@ -47,7 +47,7 @@
 
 JNIEXPORT jstring JNICALL
 Java_go_issue12403_Issue12403_00024proxyParsable_toJSON(JNIEnv* env, jobject __this__) {
-    int32_t o = go_seq_to_refnum(env, __this__);
+    int32_t o = go_seq_to_refnum_go(env, __this__);
     struct proxyissue12403_Parsable_ToJSON_return res = proxyissue12403_Parsable_ToJSON(o);
     jstring _r0 = go_seq_to_java_string(env, res.r0);
     jobject _r1 = go_seq_from_refnum(env, res.r1, proxy_class__error, proxy_class__error_cons);
diff --git a/bind/testdata/keywords.java.c.golden b/bind/testdata/keywords.java.c.golden
index adc419e..a84742d 100644
--- a/bind/testdata/keywords.java.c.golden
+++ b/bind/testdata/keywords.java.c.golden
@@ -130,7 +130,7 @@
 
 JNIEXPORT void JNICALL
 Java_go_keywords_Keywords_00024proxyKeywordCaller_abstract_1(JNIEnv* env, jobject __this__) {
-    int32_t o = go_seq_to_refnum(env, __this__);
+    int32_t o = go_seq_to_refnum_go(env, __this__);
     proxykeywords_KeywordCaller_Abstract(o);
 }
 
@@ -143,7 +143,7 @@
 
 JNIEXPORT void JNICALL
 Java_go_keywords_Keywords_00024proxyKeywordCaller_assert_1(JNIEnv* env, jobject __this__) {
-    int32_t o = go_seq_to_refnum(env, __this__);
+    int32_t o = go_seq_to_refnum_go(env, __this__);
     proxykeywords_KeywordCaller_Assert(o);
 }
 
@@ -156,7 +156,7 @@
 
 JNIEXPORT void JNICALL
 Java_go_keywords_Keywords_00024proxyKeywordCaller_boolean_1(JNIEnv* env, jobject __this__) {
-    int32_t o = go_seq_to_refnum(env, __this__);
+    int32_t o = go_seq_to_refnum_go(env, __this__);
     proxykeywords_KeywordCaller_Boolean(o);
 }
 
@@ -169,7 +169,7 @@
 
 JNIEXPORT void JNICALL
 Java_go_keywords_Keywords_00024proxyKeywordCaller_break_1(JNIEnv* env, jobject __this__) {
-    int32_t o = go_seq_to_refnum(env, __this__);
+    int32_t o = go_seq_to_refnum_go(env, __this__);
     proxykeywords_KeywordCaller_Break(o);
 }
 
@@ -182,7 +182,7 @@
 
 JNIEXPORT void JNICALL
 Java_go_keywords_Keywords_00024proxyKeywordCaller_byte_1(JNIEnv* env, jobject __this__) {
-    int32_t o = go_seq_to_refnum(env, __this__);
+    int32_t o = go_seq_to_refnum_go(env, __this__);
     proxykeywords_KeywordCaller_Byte(o);
 }
 
@@ -195,7 +195,7 @@
 
 JNIEXPORT void JNICALL
 Java_go_keywords_Keywords_00024proxyKeywordCaller_case_1(JNIEnv* env, jobject __this__) {
-    int32_t o = go_seq_to_refnum(env, __this__);
+    int32_t o = go_seq_to_refnum_go(env, __this__);
     proxykeywords_KeywordCaller_Case(o);
 }
 
@@ -208,7 +208,7 @@
 
 JNIEXPORT void JNICALL
 Java_go_keywords_Keywords_00024proxyKeywordCaller_catch_1(JNIEnv* env, jobject __this__) {
-    int32_t o = go_seq_to_refnum(env, __this__);
+    int32_t o = go_seq_to_refnum_go(env, __this__);
     proxykeywords_KeywordCaller_Catch(o);
 }
 
@@ -221,7 +221,7 @@
 
 JNIEXPORT void JNICALL
 Java_go_keywords_Keywords_00024proxyKeywordCaller_char_1(JNIEnv* env, jobject __this__) {
-    int32_t o = go_seq_to_refnum(env, __this__);
+    int32_t o = go_seq_to_refnum_go(env, __this__);
     proxykeywords_KeywordCaller_Char(o);
 }
 
@@ -234,7 +234,7 @@
 
 JNIEXPORT void JNICALL
 Java_go_keywords_Keywords_00024proxyKeywordCaller_class_1(JNIEnv* env, jobject __this__) {
-    int32_t o = go_seq_to_refnum(env, __this__);
+    int32_t o = go_seq_to_refnum_go(env, __this__);
     proxykeywords_KeywordCaller_Class(o);
 }
 
@@ -247,7 +247,7 @@
 
 JNIEXPORT void JNICALL
 Java_go_keywords_Keywords_00024proxyKeywordCaller_const_1(JNIEnv* env, jobject __this__) {
-    int32_t o = go_seq_to_refnum(env, __this__);
+    int32_t o = go_seq_to_refnum_go(env, __this__);
     proxykeywords_KeywordCaller_Const(o);
 }
 
@@ -260,7 +260,7 @@
 
 JNIEXPORT void JNICALL
 Java_go_keywords_Keywords_00024proxyKeywordCaller_continue_1(JNIEnv* env, jobject __this__) {
-    int32_t o = go_seq_to_refnum(env, __this__);
+    int32_t o = go_seq_to_refnum_go(env, __this__);
     proxykeywords_KeywordCaller_Continue(o);
 }
 
@@ -273,7 +273,7 @@
 
 JNIEXPORT void JNICALL
 Java_go_keywords_Keywords_00024proxyKeywordCaller_default_1(JNIEnv* env, jobject __this__) {
-    int32_t o = go_seq_to_refnum(env, __this__);
+    int32_t o = go_seq_to_refnum_go(env, __this__);
     proxykeywords_KeywordCaller_Default(o);
 }
 
@@ -286,7 +286,7 @@
 
 JNIEXPORT void JNICALL
 Java_go_keywords_Keywords_00024proxyKeywordCaller_do_1(JNIEnv* env, jobject __this__) {
-    int32_t o = go_seq_to_refnum(env, __this__);
+    int32_t o = go_seq_to_refnum_go(env, __this__);
     proxykeywords_KeywordCaller_Do(o);
 }
 
@@ -299,7 +299,7 @@
 
 JNIEXPORT void JNICALL
 Java_go_keywords_Keywords_00024proxyKeywordCaller_double_1(JNIEnv* env, jobject __this__) {
-    int32_t o = go_seq_to_refnum(env, __this__);
+    int32_t o = go_seq_to_refnum_go(env, __this__);
     proxykeywords_KeywordCaller_Double(o);
 }
 
@@ -312,7 +312,7 @@
 
 JNIEXPORT void JNICALL
 Java_go_keywords_Keywords_00024proxyKeywordCaller_else_1(JNIEnv* env, jobject __this__) {
-    int32_t o = go_seq_to_refnum(env, __this__);
+    int32_t o = go_seq_to_refnum_go(env, __this__);
     proxykeywords_KeywordCaller_Else(o);
 }
 
@@ -325,7 +325,7 @@
 
 JNIEXPORT void JNICALL
 Java_go_keywords_Keywords_00024proxyKeywordCaller_enum_1(JNIEnv* env, jobject __this__) {
-    int32_t o = go_seq_to_refnum(env, __this__);
+    int32_t o = go_seq_to_refnum_go(env, __this__);
     proxykeywords_KeywordCaller_Enum(o);
 }
 
@@ -338,7 +338,7 @@
 
 JNIEXPORT void JNICALL
 Java_go_keywords_Keywords_00024proxyKeywordCaller_extends_1(JNIEnv* env, jobject __this__) {
-    int32_t o = go_seq_to_refnum(env, __this__);
+    int32_t o = go_seq_to_refnum_go(env, __this__);
     proxykeywords_KeywordCaller_Extends(o);
 }
 
@@ -351,7 +351,7 @@
 
 JNIEXPORT void JNICALL
 Java_go_keywords_Keywords_00024proxyKeywordCaller_false_1(JNIEnv* env, jobject __this__) {
-    int32_t o = go_seq_to_refnum(env, __this__);
+    int32_t o = go_seq_to_refnum_go(env, __this__);
     proxykeywords_KeywordCaller_False(o);
 }
 
@@ -364,7 +364,7 @@
 
 JNIEXPORT void JNICALL
 Java_go_keywords_Keywords_00024proxyKeywordCaller_final_1(JNIEnv* env, jobject __this__) {
-    int32_t o = go_seq_to_refnum(env, __this__);
+    int32_t o = go_seq_to_refnum_go(env, __this__);
     proxykeywords_KeywordCaller_Final(o);
 }
 
@@ -377,7 +377,7 @@
 
 JNIEXPORT void JNICALL
 Java_go_keywords_Keywords_00024proxyKeywordCaller_finally_1(JNIEnv* env, jobject __this__) {
-    int32_t o = go_seq_to_refnum(env, __this__);
+    int32_t o = go_seq_to_refnum_go(env, __this__);
     proxykeywords_KeywordCaller_Finally(o);
 }
 
@@ -390,7 +390,7 @@
 
 JNIEXPORT void JNICALL
 Java_go_keywords_Keywords_00024proxyKeywordCaller_float_1(JNIEnv* env, jobject __this__) {
-    int32_t o = go_seq_to_refnum(env, __this__);
+    int32_t o = go_seq_to_refnum_go(env, __this__);
     proxykeywords_KeywordCaller_Float(o);
 }
 
@@ -403,7 +403,7 @@
 
 JNIEXPORT void JNICALL
 Java_go_keywords_Keywords_00024proxyKeywordCaller_for_1(JNIEnv* env, jobject __this__) {
-    int32_t o = go_seq_to_refnum(env, __this__);
+    int32_t o = go_seq_to_refnum_go(env, __this__);
     proxykeywords_KeywordCaller_For(o);
 }
 
@@ -416,7 +416,7 @@
 
 JNIEXPORT void JNICALL
 Java_go_keywords_Keywords_00024proxyKeywordCaller_goto_1(JNIEnv* env, jobject __this__) {
-    int32_t o = go_seq_to_refnum(env, __this__);
+    int32_t o = go_seq_to_refnum_go(env, __this__);
     proxykeywords_KeywordCaller_Goto(o);
 }
 
@@ -429,7 +429,7 @@
 
 JNIEXPORT void JNICALL
 Java_go_keywords_Keywords_00024proxyKeywordCaller_if_1(JNIEnv* env, jobject __this__) {
-    int32_t o = go_seq_to_refnum(env, __this__);
+    int32_t o = go_seq_to_refnum_go(env, __this__);
     proxykeywords_KeywordCaller_If(o);
 }
 
@@ -442,7 +442,7 @@
 
 JNIEXPORT void JNICALL
 Java_go_keywords_Keywords_00024proxyKeywordCaller_implements_1(JNIEnv* env, jobject __this__) {
-    int32_t o = go_seq_to_refnum(env, __this__);
+    int32_t o = go_seq_to_refnum_go(env, __this__);
     proxykeywords_KeywordCaller_Implements(o);
 }
 
@@ -455,7 +455,7 @@
 
 JNIEXPORT void JNICALL
 Java_go_keywords_Keywords_00024proxyKeywordCaller_import_1(JNIEnv* env, jobject __this__) {
-    int32_t o = go_seq_to_refnum(env, __this__);
+    int32_t o = go_seq_to_refnum_go(env, __this__);
     proxykeywords_KeywordCaller_Import(o);
 }
 
@@ -468,7 +468,7 @@
 
 JNIEXPORT void JNICALL
 Java_go_keywords_Keywords_00024proxyKeywordCaller_instanceof_1(JNIEnv* env, jobject __this__) {
-    int32_t o = go_seq_to_refnum(env, __this__);
+    int32_t o = go_seq_to_refnum_go(env, __this__);
     proxykeywords_KeywordCaller_Instanceof(o);
 }
 
@@ -481,7 +481,7 @@
 
 JNIEXPORT void JNICALL
 Java_go_keywords_Keywords_00024proxyKeywordCaller_int_1(JNIEnv* env, jobject __this__) {
-    int32_t o = go_seq_to_refnum(env, __this__);
+    int32_t o = go_seq_to_refnum_go(env, __this__);
     proxykeywords_KeywordCaller_Int(o);
 }
 
@@ -494,7 +494,7 @@
 
 JNIEXPORT void JNICALL
 Java_go_keywords_Keywords_00024proxyKeywordCaller_interface_1(JNIEnv* env, jobject __this__) {
-    int32_t o = go_seq_to_refnum(env, __this__);
+    int32_t o = go_seq_to_refnum_go(env, __this__);
     proxykeywords_KeywordCaller_Interface(o);
 }
 
@@ -507,7 +507,7 @@
 
 JNIEXPORT void JNICALL
 Java_go_keywords_Keywords_00024proxyKeywordCaller_long_1(JNIEnv* env, jobject __this__) {
-    int32_t o = go_seq_to_refnum(env, __this__);
+    int32_t o = go_seq_to_refnum_go(env, __this__);
     proxykeywords_KeywordCaller_Long(o);
 }
 
@@ -520,7 +520,7 @@
 
 JNIEXPORT void JNICALL
 Java_go_keywords_Keywords_00024proxyKeywordCaller_native_1(JNIEnv* env, jobject __this__) {
-    int32_t o = go_seq_to_refnum(env, __this__);
+    int32_t o = go_seq_to_refnum_go(env, __this__);
     proxykeywords_KeywordCaller_Native(o);
 }
 
@@ -533,7 +533,7 @@
 
 JNIEXPORT void JNICALL
 Java_go_keywords_Keywords_00024proxyKeywordCaller_new_1(JNIEnv* env, jobject __this__) {
-    int32_t o = go_seq_to_refnum(env, __this__);
+    int32_t o = go_seq_to_refnum_go(env, __this__);
     proxykeywords_KeywordCaller_New(o);
 }
 
@@ -546,7 +546,7 @@
 
 JNIEXPORT void JNICALL
 Java_go_keywords_Keywords_00024proxyKeywordCaller_null_1(JNIEnv* env, jobject __this__) {
-    int32_t o = go_seq_to_refnum(env, __this__);
+    int32_t o = go_seq_to_refnum_go(env, __this__);
     proxykeywords_KeywordCaller_Null(o);
 }
 
@@ -559,7 +559,7 @@
 
 JNIEXPORT void JNICALL
 Java_go_keywords_Keywords_00024proxyKeywordCaller_package_1(JNIEnv* env, jobject __this__) {
-    int32_t o = go_seq_to_refnum(env, __this__);
+    int32_t o = go_seq_to_refnum_go(env, __this__);
     proxykeywords_KeywordCaller_Package(o);
 }
 
@@ -572,7 +572,7 @@
 
 JNIEXPORT void JNICALL
 Java_go_keywords_Keywords_00024proxyKeywordCaller_private_1(JNIEnv* env, jobject __this__) {
-    int32_t o = go_seq_to_refnum(env, __this__);
+    int32_t o = go_seq_to_refnum_go(env, __this__);
     proxykeywords_KeywordCaller_Private(o);
 }
 
@@ -585,7 +585,7 @@
 
 JNIEXPORT void JNICALL
 Java_go_keywords_Keywords_00024proxyKeywordCaller_protected_1(JNIEnv* env, jobject __this__) {
-    int32_t o = go_seq_to_refnum(env, __this__);
+    int32_t o = go_seq_to_refnum_go(env, __this__);
     proxykeywords_KeywordCaller_Protected(o);
 }
 
@@ -598,7 +598,7 @@
 
 JNIEXPORT void JNICALL
 Java_go_keywords_Keywords_00024proxyKeywordCaller_public_1(JNIEnv* env, jobject __this__) {
-    int32_t o = go_seq_to_refnum(env, __this__);
+    int32_t o = go_seq_to_refnum_go(env, __this__);
     proxykeywords_KeywordCaller_Public(o);
 }
 
@@ -611,7 +611,7 @@
 
 JNIEXPORT void JNICALL
 Java_go_keywords_Keywords_00024proxyKeywordCaller_return_1(JNIEnv* env, jobject __this__) {
-    int32_t o = go_seq_to_refnum(env, __this__);
+    int32_t o = go_seq_to_refnum_go(env, __this__);
     proxykeywords_KeywordCaller_Return(o);
 }
 
@@ -624,7 +624,7 @@
 
 JNIEXPORT void JNICALL
 Java_go_keywords_Keywords_00024proxyKeywordCaller_short_1(JNIEnv* env, jobject __this__) {
-    int32_t o = go_seq_to_refnum(env, __this__);
+    int32_t o = go_seq_to_refnum_go(env, __this__);
     proxykeywords_KeywordCaller_Short(o);
 }
 
@@ -637,7 +637,7 @@
 
 JNIEXPORT void JNICALL
 Java_go_keywords_Keywords_00024proxyKeywordCaller_static_1(JNIEnv* env, jobject __this__) {
-    int32_t o = go_seq_to_refnum(env, __this__);
+    int32_t o = go_seq_to_refnum_go(env, __this__);
     proxykeywords_KeywordCaller_Static(o);
 }
 
@@ -650,7 +650,7 @@
 
 JNIEXPORT void JNICALL
 Java_go_keywords_Keywords_00024proxyKeywordCaller_strictfp_1(JNIEnv* env, jobject __this__) {
-    int32_t o = go_seq_to_refnum(env, __this__);
+    int32_t o = go_seq_to_refnum_go(env, __this__);
     proxykeywords_KeywordCaller_Strictfp(o);
 }
 
@@ -663,7 +663,7 @@
 
 JNIEXPORT void JNICALL
 Java_go_keywords_Keywords_00024proxyKeywordCaller_super_1(JNIEnv* env, jobject __this__) {
-    int32_t o = go_seq_to_refnum(env, __this__);
+    int32_t o = go_seq_to_refnum_go(env, __this__);
     proxykeywords_KeywordCaller_Super(o);
 }
 
@@ -676,7 +676,7 @@
 
 JNIEXPORT void JNICALL
 Java_go_keywords_Keywords_00024proxyKeywordCaller_switch_1(JNIEnv* env, jobject __this__) {
-    int32_t o = go_seq_to_refnum(env, __this__);
+    int32_t o = go_seq_to_refnum_go(env, __this__);
     proxykeywords_KeywordCaller_Switch(o);
 }
 
@@ -689,7 +689,7 @@
 
 JNIEXPORT void JNICALL
 Java_go_keywords_Keywords_00024proxyKeywordCaller_synchronized_1(JNIEnv* env, jobject __this__) {
-    int32_t o = go_seq_to_refnum(env, __this__);
+    int32_t o = go_seq_to_refnum_go(env, __this__);
     proxykeywords_KeywordCaller_Synchronized(o);
 }
 
@@ -702,7 +702,7 @@
 
 JNIEXPORT void JNICALL
 Java_go_keywords_Keywords_00024proxyKeywordCaller_this_1(JNIEnv* env, jobject __this__) {
-    int32_t o = go_seq_to_refnum(env, __this__);
+    int32_t o = go_seq_to_refnum_go(env, __this__);
     proxykeywords_KeywordCaller_This(o);
 }
 
@@ -715,7 +715,7 @@
 
 JNIEXPORT void JNICALL
 Java_go_keywords_Keywords_00024proxyKeywordCaller_throw_1(JNIEnv* env, jobject __this__) {
-    int32_t o = go_seq_to_refnum(env, __this__);
+    int32_t o = go_seq_to_refnum_go(env, __this__);
     proxykeywords_KeywordCaller_Throw(o);
 }
 
@@ -728,7 +728,7 @@
 
 JNIEXPORT void JNICALL
 Java_go_keywords_Keywords_00024proxyKeywordCaller_throws_1(JNIEnv* env, jobject __this__) {
-    int32_t o = go_seq_to_refnum(env, __this__);
+    int32_t o = go_seq_to_refnum_go(env, __this__);
     proxykeywords_KeywordCaller_Throws(o);
 }
 
@@ -741,7 +741,7 @@
 
 JNIEXPORT void JNICALL
 Java_go_keywords_Keywords_00024proxyKeywordCaller_transient_1(JNIEnv* env, jobject __this__) {
-    int32_t o = go_seq_to_refnum(env, __this__);
+    int32_t o = go_seq_to_refnum_go(env, __this__);
     proxykeywords_KeywordCaller_Transient(o);
 }
 
@@ -754,7 +754,7 @@
 
 JNIEXPORT void JNICALL
 Java_go_keywords_Keywords_00024proxyKeywordCaller_true_1(JNIEnv* env, jobject __this__) {
-    int32_t o = go_seq_to_refnum(env, __this__);
+    int32_t o = go_seq_to_refnum_go(env, __this__);
     proxykeywords_KeywordCaller_True(o);
 }
 
@@ -767,7 +767,7 @@
 
 JNIEXPORT void JNICALL
 Java_go_keywords_Keywords_00024proxyKeywordCaller_try_1(JNIEnv* env, jobject __this__) {
-    int32_t o = go_seq_to_refnum(env, __this__);
+    int32_t o = go_seq_to_refnum_go(env, __this__);
     proxykeywords_KeywordCaller_Try(o);
 }
 
@@ -780,7 +780,7 @@
 
 JNIEXPORT void JNICALL
 Java_go_keywords_Keywords_00024proxyKeywordCaller_void_1(JNIEnv* env, jobject __this__) {
-    int32_t o = go_seq_to_refnum(env, __this__);
+    int32_t o = go_seq_to_refnum_go(env, __this__);
     proxykeywords_KeywordCaller_Void(o);
 }
 
@@ -793,7 +793,7 @@
 
 JNIEXPORT void JNICALL
 Java_go_keywords_Keywords_00024proxyKeywordCaller_volatile_1(JNIEnv* env, jobject __this__) {
-    int32_t o = go_seq_to_refnum(env, __this__);
+    int32_t o = go_seq_to_refnum_go(env, __this__);
     proxykeywords_KeywordCaller_Volatile(o);
 }
 
@@ -806,7 +806,7 @@
 
 JNIEXPORT void JNICALL
 Java_go_keywords_Keywords_00024proxyKeywordCaller_while_1(JNIEnv* env, jobject __this__) {
-    int32_t o = go_seq_to_refnum(env, __this__);
+    int32_t o = go_seq_to_refnum_go(env, __this__);
     proxykeywords_KeywordCaller_While(o);
 }
 
diff --git a/bind/testdata/structs.java.c.golden b/bind/testdata/structs.java.c.golden
index 5438570..9b84a2f 100644
--- a/bind/testdata/structs.java.c.golden
+++ b/bind/testdata/structs.java.c.golden
@@ -60,7 +60,7 @@
 
 JNIEXPORT jobject JNICALL
 Java_go_structs_S_identity(JNIEnv* env, jobject __this__) {
-    int32_t o = go_seq_to_refnum(env, __this__);
+    int32_t o = go_seq_to_refnum_go(env, __this__);
     struct proxystructs_S_Identity_return res = proxystructs_S_Identity(o);
     jobject _r0 = go_seq_from_refnum(env, res.r0, proxy_class_structs_S, proxy_class_structs_S_cons);
     jobject _r1 = go_seq_from_refnum(env, res.r1, proxy_class__error, proxy_class__error_cons);
@@ -70,7 +70,7 @@
 
 JNIEXPORT jdouble JNICALL
 Java_go_structs_S_sum(JNIEnv* env, jobject __this__) {
-    int32_t o = go_seq_to_refnum(env, __this__);
+    int32_t o = go_seq_to_refnum_go(env, __this__);
     double r0 = proxystructs_S_Sum(o);
     jdouble _r0 = (jdouble)r0;
     return _r0;
@@ -78,14 +78,14 @@
 
 JNIEXPORT void JNICALL
 Java_go_structs_S_setX(JNIEnv *env, jobject this, jdouble v) {
-    int32_t o = go_seq_to_refnum(env, this);
+    int32_t o = go_seq_to_refnum_go(env, this);
     double _v = (double)v;
     proxystructs_S_X_Set(o, _v);
 }
 
 JNIEXPORT jdouble JNICALL
 Java_go_structs_S_getX(JNIEnv *env, jobject this) {
-    int32_t o = go_seq_to_refnum(env, this);
+    int32_t o = go_seq_to_refnum_go(env, this);
     double r0 = proxystructs_S_X_Get(o);
     jdouble _r0 = (jdouble)r0;
     return _r0;
@@ -93,14 +93,14 @@
 
 JNIEXPORT void JNICALL
 Java_go_structs_S_setY(JNIEnv *env, jobject this, jdouble v) {
-    int32_t o = go_seq_to_refnum(env, this);
+    int32_t o = go_seq_to_refnum_go(env, this);
     double _v = (double)v;
     proxystructs_S_Y_Set(o, _v);
 }
 
 JNIEXPORT jdouble JNICALL
 Java_go_structs_S_getY(JNIEnv *env, jobject this) {
-    int32_t o = go_seq_to_refnum(env, this);
+    int32_t o = go_seq_to_refnum_go(env, this);
     double r0 = proxystructs_S_Y_Get(o);
     jdouble _r0 = (jdouble)r0;
     return _r0;
@@ -114,13 +114,13 @@
 
 JNIEXPORT void JNICALL
 Java_go_structs_S2_m(JNIEnv* env, jobject __this__) {
-    int32_t o = go_seq_to_refnum(env, __this__);
+    int32_t o = go_seq_to_refnum_go(env, __this__);
     proxystructs_S2_M(o);
 }
 
 JNIEXPORT jstring JNICALL
 Java_go_structs_S2_string(JNIEnv* env, jobject __this__) {
-    int32_t o = go_seq_to_refnum(env, __this__);
+    int32_t o = go_seq_to_refnum_go(env, __this__);
     nstring r0 = proxystructs_S2_String(o);
     jstring _r0 = go_seq_to_java_string(env, r0);
     return _r0;
@@ -128,7 +128,7 @@
 
 JNIEXPORT void JNICALL
 Java_go_structs_Structs_00024proxyI_m(JNIEnv* env, jobject __this__) {
-    int32_t o = go_seq_to_refnum(env, __this__);
+    int32_t o = go_seq_to_refnum_go(env, __this__);
     proxystructs_I_M(o);
 }
 
diff --git a/bind/testpkg/javapkg/classes.go b/bind/testpkg/javapkg/classes.go
index a6545d0..a2ac93a 100644
--- a/bind/testpkg/javapkg/classes.go
+++ b/bind/testpkg/javapkg/classes.go
@@ -28,6 +28,8 @@
 	lang.Object
 	lang.Runnable
 	this lang.Runnable
+
+	Field string
 }
 
 func (r *GoRunnable) ToString(this lang.Runnable) string {