compute(int value1, int value2)
method in our Script
interface with two int values as arguments. However if we used the script with other numbers, the method will throw an exception.
MethodWrapeprImpl2
class:public class MethodWrapperImpl2 extends AbstractScriptMethodWrapper<Script, Integer> { public MethodWrapperImpl2(ScriptWrapper<Script> wrapper) { super(wrapper); checkDeclaredArguments("compute", Integer.class, Integer.class); } protected Integer executeScriptImpl(Object[] arguments) { Integer i1 = (Integer)arguments[0]; Integer i2 = (Integer)arguments[1]; return script.compute(i1, i2); } }
int value = methodWrapper2.executeMethod(1f, 2f);The method will perform correctly because the float arguments will be converted to int values.
Copyright 2019-2020 Herve Girod. All Rights Reserved. Documentation and source under the BSD licence