Fix std::vector<> Java typemaps for primitive types

For such types, the generated proxy class inherited from
java.util.AbstractSet<BoxedType<T>> (where BoxedType<T> is "Integer",
for example, when T is "int"), but defined an overloaded add() taking T,
instead of overriding the base class virtual add() taking BoxedType<T>,
resulting in an exception being thrown whenever add() was called during
run-time.

Extend Java unit test to bring it to parity with C# one added in the
previous commit.

See #1568.
This commit is contained in:
Vadim Zeitlin 2019-07-11 13:07:10 +02:00
parent 28c6140c56
commit 2be293a647
3 changed files with 14 additions and 4 deletions

View File

@ -77,5 +77,14 @@ public class li_std_set_runme {
checkThat(fooSet.isEmpty());
checkThat(fooSet.add(new Foo(17)));
checkThat(fooSet.size() == 1);
// And a set of primitive type.
java.util.AbstractSet<Integer> intSet = new IntSet();
checkThat(intSet.isEmpty());
checkThat(intSet.add(17));
checkThat(!intSet.add(17));
checkThat(intSet.size() == 1);
checkThat(intSet.add(289));
checkThat(intSet.size() == 2);
}
}

View File

@ -40,10 +40,7 @@
};
%}
// This one doesn't work in Java correctly yet.
#ifdef SWIGCSHARP
%template(IntSet) std::set<int>;
#endif
%template(StringSet) std::set<std::string>;
%template(FooSet) std::set<Foo>;
#endif

View File

@ -57,6 +57,10 @@ class set {
return sizeImpl();
}
public boolean add($typemap(jboxtype, T) key) {
return addImpl(key);
}
public boolean addAll(java.util.Collection<? extends $typemap(jboxtype, T)> collection) {
boolean didAddElement = false;
for (java.lang.Object object : collection) {
@ -172,7 +176,7 @@ class set {
%fragment("SWIG_SetSize");
// Returns whether item was inserted.
bool add(const T& key) {
bool addImpl(const T& key) {
return self->insert(key).second;
}