bind: don't throw away result values with unknown type

The Java API wrapper generator use interface{} for Java classes
that no Go code references. Return values of unknown types are thrown
away, since they're effectively useless. Since the return values can
be used for nil checks and since casting of Java instances are
supported in CL 30095, this CL returns the naked *seq.Ref results
values instead.

Change-Id: I821b1c344a4c68c57fd34e2b655404e449de4c03
Reviewed-on: https://go-review.googlesource.com/30097
Reviewed-by: David Crawshaw <crawshaw@golang.org>
diff --git a/bind/genclasses.go b/bind/genclasses.go
index 0de3f23..30f375d 100644
--- a/bind/genclasses.go
+++ b/bind/genclasses.go
@@ -573,9 +573,11 @@
 	g.Printf("if %s_ref != nil {\n", to)
 	g.Printf("	if %s < 0 { // go object\n", from)
 	g.Printf("		%s = %s_ref.Get().(%s)\n", to, to, intfName)
+	g.Printf("	} else { // foreign object\n")
 	if hasProxy {
-		g.Printf("	} else { // foreign object\n")
 		g.Printf("		%s = (*%s)(%s_ref)\n", to, proxyName, to)
+	} else {
+		g.Printf("		%s = %s_ref\n", to, to)
 	}
 	g.Printf("	}\n")
 	g.Printf("}\n")
diff --git a/bind/java/ClassesTest.java b/bind/java/ClassesTest.java
index 6193307..720fc75 100644
--- a/bind/java/ClassesTest.java
+++ b/bind/java/ClassesTest.java
@@ -108,6 +108,12 @@
 		assertEquals("IOException message", Javapkg.IOExceptionMessage, exc.getMessage());
 	}
 
+	public void testUnknownType() {
+		GoObject o = new GoObject();
+		o.toString(); // Set this
+		assertTrue("GoObject.getClass not null", o.checkClass());
+	}
+
 	public void testInnerClass() {
 		Character.Subset s = new Character.Subset(""){};
 		Character.Subset s2 = new GoSubset("");
diff --git a/bind/testpkg/javapkg/classes.go b/bind/testpkg/javapkg/classes.go
index 865c0ab..834dce7 100644
--- a/bind/testpkg/javapkg/classes.go
+++ b/bind/testpkg/javapkg/classes.go
@@ -77,12 +77,22 @@
 
 type GoObject struct {
 	lang.Object
+	this lang.Object
 }
 
-func (_ *GoObject) ToString(this lang.Object) string {
+func (o *GoObject) ToString(this lang.Object) string {
+	o.this = this
 	return ToStringPrefix + this.Super().ToString()
 }
 
+func (r *GoObject) CheckClass() bool {
+	// Verify that GetClass returns interface{} because java.lang.Class
+	// is unreferenced.
+	var f func() interface{} = r.this.GetClass
+	// But it should return a value
+	return f() != nil
+}
+
 func (_ *GoObject) HashCode() int32 {
 	return 42
 }