Invalid binding for java.util.SortedMap
- Dominant language
- C#
- Stars
- 2.1k
- Forks
- 579
- Avg merge
- 1d 19h
- Merged PRs (30d)
- 252
Description
Today we bind `java.util.SortedMap` as `Android.Runtime.JavaDictionary` so it feels more like using .NET types. However, `JavaDictionary` does not implement `ISortedMap`, causing this error when attempting to use the type at runtime:
```
JNI ERROR (app bug): attempt to pass an instance of java.util.HashMap as argument 1 to void org.osmdroid.views.overlay.advancedpolyline.ColorMappingRanges.(java.util.SortedMap)
```
Code specifying this conversion:
https://github.com/xamarin/java.interop/blob/master/tools/generator/Java.Interop.Tools.Generator.ObjectModel/Symbols/SymbolTable.cs#L212
To fix this we will need to create something like `JavaSortedDictionary` and map it to `java.util.SortedMap`.
### Workaround
To work around this, the generated member can be deleted via `metadata` and manually bound to a type which implements `SortedMap` (`TreeMap`) with an `Addition`.
For example, here is a constructor that takes a `java.util.SortedMap`:
```
public Foo (final TreeMap p0)
{
const string __id = "(Ljava/util/SortedMap;)V";
if (((global::Java.Lang.Object) this).Handle != IntPtr.Zero)
return;
IntPtr native_p0 = JNIEnv.ToLocalJniHandle (p0);
try {
JniArgumentValue* __args = stackalloc JniArgumentValue [1];
__args [0] = new JniArgumentValue (native_p0);
var __r = _members.InstanceMethods.StartCreateInstance (__id, ((object) this).GetType (), __args);
SetHandle (__r.Handle, JniHandleOwnership.TransferLocalRef);
_members.InstanceMethods.FinishCreateInstance (__id, this, __args);
} finally {
JNIEnv.DeleteLocalRef (native_p0);
}
}
```
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.