【发布时间】:2017-01-20 08:18:40
【问题描述】:
在过去的一个小时里我一直在努力让它工作,我收到了错误
只能遍历数组或 java.lang.Iterable 的实例
public boolean register(Object parent, Class<?>... events) {
boolean added = false;
try {
for (Link<?> link : parentLinkCache.get((List) Objects.requireNonNull(parent, "Object to be registered cannot be null"))) {
if (events.length > 0) {
for (Class<?> clazz : events) {
if (link.getEventClass() == clazz) {
this.backingMap.computeIfAbsent(link.getEventClass(), l -> new ConcurrentSkipListSet<>()).add(link);
added = true;
break;
}
}
} else {
this.backingMap.computeIfAbsent(link.getEventClass(), l -> new ConcurrentSkipListSet<>()).add(link);
added = true;
}
}
} catch (ExecutionException e) {
e.printStackTrace();
}
return added;
}
错误出现在parentLinkCache.get。
【问题讨论】:
-
parentLinkCache.get(...)返回什么类型的对象?它不是实现Iterable<Link<?>>的数组或类型。 -
私有静态最终LoadingCache
-
parentLinkCache.get会返回一个Object;那不是Iterable。