[英]Exception when calling overloaded static method using JSR223
I'm trying to implement a rule for openHAB ( http://www.openhab.org/ ) in Javascript using JSR223 ( https://github.com/openhab/openhab/wiki/Jsr223-Script-Engine ). 我正在尝试使用JSR223( https://github.com/openhab/openhab/wiki/Jsr223-Script-Engine )在Javascript中实现openHAB( http://www.openhab.org/ )的规则。
Anyone having a suggestion of the root cause of following exception? 是否有人提出以下异常的根本原因? Remark that both instances passed as argument implement the interfaces used as parameters in the method declaration.
请注意,作为参数传递的两个实例都实现了在方法声明中用作参数的接口。
java.lang.RuntimeException: java.lang.NoSuchMethodException: None of the fixed arity signatures [(org.openhab.core.items.Item, org.joda.time.base.AbstractInstant)] of method org.openhab.core.persistence.extensions.PersistenceExtensions.changedSince match the argument types [org.openhab.core.items.GroupItem, org.joda.time.DateTime]
at jdk.nashorn.javaadapters.java.util.function.Consumer.accept(Unknown Source) ~[na:na]
at java.util.ArrayList.forEach(ArrayList.java:1249) ~[na:1.8.0_31]
at jdk.nashorn.internal.scripts.Script$\^eval\_.L:13(<eval>:14) ~[na:na]
at org.openhab.core.jsr223.internal.shared.Rule$$NashornJavaAdapter.execute(Unknown Source) ~[na:na]
at org.openhab.core.jsr223.internal.engine.RuleExecutionRunnable.run(RuleExecutionRunnable.java:36) ~[na:na]
at java.lang.Thread.run(Thread.java:745) [na:1.8.0_31]
Following is the implemented script: 以下是已实现的脚本:
'use strict';
load("nashorn:mozilla_compat.js");
importPackage(org.openhab.core.jsr223.internal.shared);
importPackage(org.joda.time);
importPackage(org.joda.time.base);
var autoOffRule = new org.openhab.core.jsr223.internal.shared.Rule() {
getEventTrigger: function() {
return [
new org.openhab.core.jsr223.internal.shared.TimerTrigger("* * * * * ?")
];
},
execute: function(event) {
for each(var item in ItemRegistry.getItems()) {
if (item.getState() == org.openhab.core.library.types.OnOffType.ON) {
var dateTime = org.joda.time.DateTime.now().withFieldAdded(DurationFieldType.seconds(), -5);
if (!(org.openhab.core.persistence.extensions.PersistenceExtensions.class.static.changedSince(item, var dateTime))) {
print("Auto-off for " + item.getName())
}
}
}
}
};
function getRules() {
return new org.openhab.core.jsr223.internal.shared.RuleSet([ autoOffRule ]);
}
The called method is overloaded and has following signatures: 被调用的方法已重载,并且具有以下签名:
org.openhab.core.persistence.extensions.PersistenceExtensions#changedSince(org.openhab.core.items.Item, org.joda.time.base.AbstractInstant)
org.openhab.core.persistence.extensions.PersistenceExtensions#changedSince(org.openhab.core.items.Item, org.joda.time.base.AbstractInstant, java.lang.String)
Tested and failing both on jdk1.8.0_31 and jdk1.8.0_65. 已在jdk1.8.0_31和jdk1.8.0_65上测试并均失败。 Bumped into a more or less a similar exception having a rule implemented in Groovy.
在Groovy中实现了与规则差不多的异常。
I know that I'm a necromantic when answering this question but I stumbled upon it and couldn't resist. 我知道我在回答这个问题时是个坏人,但我偶然发现了它,无法抗拒。
The error message is clear: You try to invoke the Java Method org.openhab.core.persistence.extensions.PersistenceExtensions.changedSince(org.openhab.core.items.Item, org.joda.time.DateTime)
with a GroupItem
. 该错误信息是明确的:您尝试调用的Java方法
org.openhab.core.persistence.extensions.PersistenceExtensions.changedSince(org.openhab.core.items.Item, org.joda.time.DateTime)
与GroupItem
。
Which is interesting since a GroupItem
extends the GenericItem
which implements the Item
Interface and therefore should match the method signature. 这很有趣,因为
GroupItem
扩展了实现Item
接口的GenericItem
,因此应该与方法签名匹配。
With for each(var item in ItemRegistry.getItems()) {
you get all items from your OpenHab Item Definition including all groups. for each(var item in ItemRegistry.getItems()) {
您将从OpenHab项定义中获取所有项,包括所有组。 You probably only want the real items. 您可能只想要真实的物品。 Try
if (! item.members )
to filter all groups. 尝试
if (! item.members )
过滤所有组。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.