Closed SmallChi closed 2 years ago
Can you post the Java you are trying to bind?
It looks like your MutableShort
class does not have a setValue
method.
java
package org.apache.commons.lang3.mutable;
public interface Mutable<T> {
T getValue();
void setValue(T paramT);
}
public class MutableShort extends Number implements Comparable<MutableShort>, Mutable<Number> {
private static final long serialVersionUID = -2135791679L;
private short value;
public MutableShort() {}
public MutableShort(short value) {
this.value = value;
}
public MutableShort(Number value) {
this.value = value.shortValue();
}
public MutableShort(String value) throws NumberFormatException {
this.value = Short.parseShort(value);
}
public Short getValue() {
return Short.valueOf(this.value);
}
public void setValue(short value) {
this.value = value;
}
public void setValue(Number value) {
this.value = value.shortValue();
}
public void increment() {
this.value = (short)(this.value + 1);
}
public void decrement() {
this.value = (short)(this.value - 1);
}
public void add(short operand) {
this.value = (short)(this.value + operand);
}
public void add(Number operand) {
this.value = (short)(this.value + operand.shortValue());
}
public void subtract(short operand) {
this.value = (short)(this.value - operand);
}
public void subtract(Number operand) {
this.value = (short)(this.value - operand.shortValue());
}
public short shortValue() {
return this.value;
}
public int intValue() {
return this.value;
}
public long longValue() {
return this.value;
}
public float floatValue() {
return this.value;
}
public double doubleValue() {
return this.value;
}
public Short toShort() {
return Short.valueOf(shortValue());
}
public boolean equals(Object obj) {
if (obj instanceof MutableShort)
return (this.value == ((MutableShort)obj).shortValue());
return false;
}
public int hashCode() {
return this.value;
}
public int compareTo(MutableShort other) {
short anotherVal = other.value;
return (this.value < anotherVal) ? -1 : ((this.value == anotherVal) ? 0 : 1);
}
public String toString() {
return String.valueOf(this.value);
}
}
I wonder if the issue is that the getter is Short
and the setter is short
:
public Short getValue() {
return Short.valueOf(this.value);
}
public void setValue(short value) {
this.value = value;
}
I think these get treated differently since JNI thinks one is a short
primitive type (S
) and the other is an object type (Ljava/lang/Short;
). If you can change the Java code so they match that would be my first suggestion.
If not, you can try changing them to match using metadata
@managedType
. I do not know if JNI will complain when we try to marshal an object instead of a short (or vice versa).
Alternatively you can use metadata
@propertyName
set to an empty string on all the getters/setters and they will not be converted to a property at all.
https://github.com/xamarin/java.interop/wiki/Troubleshooting-Android-Bindings-Issues
Thank you very much for the method you provided, since this is an aar package provided by a third party, viewed through the JD-JUI tool, so the Java code cannot be changed, so it can only be modified through the metadata configuration.😎
generated
Error CS0200 cannot assign a Value to the attribute or indexer "MutableShort.Value" - it is read-only
Hope wants!
How do I need to modify metadata.xml to meet expectations, or is there a good way to solve this problem.