我正在使用 rhino API 调用 JavaScript 函数:
Function fct = context.compileFunction(scope, script, "script", 1, null);
Scriptable result = (Scriptable) fct.call(
context, scope, attrs, new Object[0]);
Object obj = result.get("objectClass", result);
现在,如何测试“objectClass”属性的值是否为数组?
最佳答案
这可能会给您一些想法:声明一个函数来确定对象是否是数组并调用该函数传递您的对象。
engine.eval("function isArray(obj) {" +
" return obj.constructor == Array;" +
"}");
Object obj = engine.eval("[1,2,3,4]");
Invocable invocableEngine = (Invocable) engine;
System.out.println(invocableEngine.invokeFunction("isArray", obj)); //true
关于java - 如何知道一个属性是否是一个数组?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3370021/