}
/**
+ * Convert an object x into another one according to base Class
+ * @param x the object to convert
+ * @param base the base Class
+ * @return the converted object
+ */
+ public static final Object convert(Object x, Class base) {
+ if (x == null) {
+ return null;
+ }
+ final Class clazz = x.getClass();
+ if (base.isAssignableFrom(clazz)) {
+ return x;
+ }
+ for (Converter converter : converters) {
+ if (converter.canConvert(clazz, base)) {
+ return converter.convert(x, base);
+ }
+ }
+
+ return x;
+ }
+
+ /**
* To find the "correct" method we proceed as follow:
* i) We calculate the distance between the Class of the arguments.
* For a Class B which derivates from A (A.isAssignableFrom(B) == true), the distance between A and B is the number of
if (obj != null && obj.getClass().isArray()) {
if (index[i] >= 0 && index[i] < Array.getLength(obj)) {
try {
- Array.set(obj, index[i], x);
+ Array.set(obj, index[i], FunctionArguments.convert(x, obj.getClass().getComponentType()));
} catch (IllegalArgumentException e) {
throw new ScilabJavaException("Array " + obj + " cannot contain object which is an instance of " + x.getClass());
}
assert_checkequal(length(str), length(a(2, 1, 3)));
assert_checkequal(str, a(2, 1, 3));
assert_checkequal(a(1), ["" ""; "" ""; "Hi Jims !" ""]);
+a = jarray("int", 1);
+a(1) = 2;
+assert_checkequal(2, double(a(1)));
assert_checkequal(length(str), length(a(2, 1, 3)));
assert_checkequal(str, a(2, 1, 3));
-assert_checkequal(a(1), ["" ""; "" ""; "Hi Jims !" ""]);
\ No newline at end of file
+assert_checkequal(a(1), ["" ""; "" ""; "Hi Jims !" ""]);
+
+a = jarray("int", 1);
+a(1) = 2;
+
+assert_checkequal(2, double(a(1)));