java - NoSuchMethodError 而不是调用正确的方法
问题描述
我遇到了一个奇怪的行为。以下代码:
private void setSegments(Set<Long> segments) {
this.segments = ImmutableSet.copyOf(segments);
}
投掷
java.lang.NoSuchMethodError: com.google.common.collect.ImmutableSet.copyOf(Ljava/util/Collection;)Lcom/google/common/collect/ImmutableSet;
我通过在方法中添加以下片段来通过反射检查类内容:
try {
Class c = ImmutableSet.class;
Method[] m = c.getDeclaredMethods();
for (int i = 0; i < m.length; i++) {
LOGGER.error("method: " + m[i].toString());
}
} catch (Throwable e) {
System.err.println(e);
}
其中,在所有其他方法中,打印出来
Segments:method: public static com.google.common.collect.ImmutableSet com.google.common.collect.ImmutableSet.copyOf(java.util.Iterator)
Segments:method: public static com.google.common.collect.ImmutableSet com.google.common.collect.ImmutableSet.copyOf(java.lang.Iterable)
我不明白为什么不调用带有 Iterable 参数的方法。毕竟,Set 扩展了实现 Iterable 的 Collection。
感谢您的任何想法
解决方案
推荐阅读
- python - 如何使用微调的 BERT 模型进行句子编码?
- image - 为什么 Scilab 不打开图像文件?
- javascript - jsGrid在编辑功能中改变输入的类型
- email - 如何触发在启用逻辑应用程序之前到达的实际电子邮件的运行?
- android - kotlinx 序列化。反序列化泛型参数麻烦
- android - 使用广播接收器以编程方式检查开发人员选项
- java - 如何在 optional.orElseThrow(..) 中抛出异常之前执行操作
- angular - mat-autocomplete 在 mat-table 内不起作用
- postgresql - 无法将 Ldap 添加到 PGAdmin
- jquery - JQuery Ajax UrlAction 更改页面 URL MVC