On Friday, March 15, 2019 at 6:30:25 PM UTC+1, kevin.h...@twomen.com wrote: > > I am attempting to update a service package which was written to be used > on mobile devices by using the gomobile bind package. It appears there was > a change made in this commit > <https://github.com/golang/mobile/commit/5b452fe89a0b199588ec21f052cd77261b55a83a#diff-55c997bb7d453dee310f6086580934f5> > > which causes a custom Int32 wrapper to generate duplicate constructors in > the generate java which errors during compilation. The current Int32 > wrapper was written to keep nullability across language boundaries, and was > written as follows > > type Int32 struct{value int32} > > fun NewInt32(value int32)*Int32 { return &Int32{value} } > > This code used to result in the generated java that follows which has two > different constructors. > > public final class Int32 implements Proxy { > private final Ref ref; > > public final int incRefnum() { > int var1 = this.ref.refnum; > Seq.incGoRef(var1); > return var1; > } > > public Int32(int var1) { > this.ref = __NewInt32(var1); > } > > private static native Ref __NewInt32(int var0); > > Int32(Ref var1) { > this.ref = var1; > } > > public native byte[] marshalJSON() throws Exception; > > public native int value(); > > public boolean equals(Object var1) { > if (var1 != null && var1 instanceof Int32) { > Int32 var2 = (Int32)var1; > return true; > } else { > return false; > } > } > > public int hashCode() { > return Arrays.hashCode(new Object[0]); > } > > public String toString() { > StringBuilder var1 = new StringBuilder(); > var1.append("Int32").append("{"); > return var1.append("}").toString(); > } > > static { > Ecaas.touch(); > } > } > > > Now it generates the following which has duplicate constructors > > public final class Int32 implements Seq.Proxy { > static { Ecaas.touch(); } > private final int refnum; > @Override public final int incRefnum() { > Seq.incGoRef(refnum, this); > return refnum; > } > public Int32(int value) { > this.refnum = __NewInt32(value); > Seq.trackGoRef(refnum, this); > } > private static native int __NewInt32(int value); > Int32(int refnum) { this.refnum = refnum; Seq.trackGoRef(refnum, this); } > public native byte[] marshalJSON() throws Exception; > public native int value(); > @Override public boolean equals(Object o) { > if (o == null || !(o instanceof Int32)) { > return false; > } > Int32 that = (Int32)o; > return true; > } > @Override public int hashCode() { > return java.util.Arrays.hashCode(new Object[] {}); > } > @Override public String toString() { > StringBuilder b = new StringBuilder(); > b.append("Int32").append("{"); > return b.append("}").toString(); > } > } > > I have looked into these nullable wrappers, and it seems the more common > patter is to use a `valid` boolean instead of directly referencing a nil > pointer. It would be a large refactor to implement, and I am wondering if > there are any better options which would result in code that complies > without refactoring the entire service for an updated wrapper which would > change the constructor signature to not be duplicated. > > >
I believe https://go-review.googlesource.com/c/mobile/+/167660 fixes the issue. Please try it out, or wait for it to be submitted to the gomobile repository. - elias -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.