mirror of
https://github.com/netbirdio/gomobile-tvos-fork.git
synced 2026-05-22 18:43:29 -07:00
bind, bind/java: support generating exceptional constructors
In Go type constructors can often return an error type too beside an instance of the type being created. This is useful in cases where the parameters might be wrong and instantiaion cannot succeed. This CL extends the Java generator so that these methods are also converted into class constructors that also can throw. Change-Id: I5e531eec126904a026767a8503968255b9fd833b Reviewed-on: https://go-review.googlesource.com/31184 Reviewed-by: Elias Naur <elias.naur@gmail.com>
This commit is contained in:
committed by
Elias Naur
parent
4cb3e7f634
commit
2ea7e2cc92
+18
-3
@@ -530,12 +530,27 @@ public class SeqTest extends InstrumentationTestCase {
|
||||
public void testConstructor() {
|
||||
Interface i = new Concrete();
|
||||
i.f();
|
||||
|
||||
S2 s = new S2(1, 2);
|
||||
assertEquals("new S2().sum", 3.0, s.sum());
|
||||
assertEquals("new S2().tryTwoStrings", "gostring", s.tryTwoStrings("go", "string"));
|
||||
new S3();
|
||||
S4 s4 = new S4(123);
|
||||
assertEquals("Constructor argument", 123, s4.getI());
|
||||
|
||||
new S3();
|
||||
|
||||
S4 s4 = new S4(123);
|
||||
assertEquals("Constructor argument", 123, s4.getI());
|
||||
|
||||
s4 = new S4(123.456);
|
||||
assertEquals("Overloaded constructor argument", 123, s4.getI());
|
||||
|
||||
s4 = new S4(false);
|
||||
assertEquals("Exceptional constructor", 0, s4.getI());
|
||||
|
||||
try {
|
||||
s4 = new S4(true);
|
||||
fail("Constructor error wasn't caught");
|
||||
} catch (Exception e) {
|
||||
}
|
||||
}
|
||||
|
||||
public void testEmptyError() {
|
||||
|
||||
Reference in New Issue
Block a user