mirror of
https://github.com/netbirdio/gomobile-tvos-fork.git
synced 2026-05-22 18:43:29 -07:00
bind,internal/importers: add Unwrap methods to unwrap Java wrappers
For Java classes implemented in Go, it is useful to take a Java instance
and extract its wrapped Go instance. For example, consider the
java.lang.Runnable implementation wrapping a Go function:
package somepkg
type GoRunnable struct {
lang.Runnable
f func()
}
Java methods that take a java.lang.Runnable cannot directly take a
*GoRunnable, so this CL adds a Unwrap method:
import gorun "Java/somepkg/GoRunnable"
...
r := gorun.New()
r.Unwrap().(*GoRunnable).f = func() { ... }
javapkg.Run(r)
The extra interface conversion is unfortunately needed to avoid
import cycles.
Change-Id: Ib775a5712cd25aa75a19d364a55d76b1e11dce77
Reviewed-on: https://go-review.googlesource.com/35295
Reviewed-by: David Crawshaw <crawshaw@golang.org>
This commit is contained in:
@@ -18,6 +18,7 @@ import javapkg.GoObject;
|
||||
import javapkg.GoRunnable;
|
||||
import javapkg.GoSubset;
|
||||
import javapkg.GoInputStream;
|
||||
import javapkg.GoArrayList;
|
||||
|
||||
public class ClassesTest extends InstrumentationTestCase {
|
||||
public void testConst() {
|
||||
@@ -148,4 +149,9 @@ public class ClassesTest extends InstrumentationTestCase {
|
||||
Runnable r4c = Javapkg.castRunnable(new Object());
|
||||
assertTrue("Invalid cast", r4c == null);
|
||||
}
|
||||
|
||||
public void testUnwrap() {
|
||||
GoArrayList l = new GoArrayList();
|
||||
Javapkg.unwrapGoArrayList(l);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user