【发布时间】:2017-04-17 15:49:59
【问题描述】:
我已经定义了这个方法:
public static TreeSet<ItemStack> getItems() {
TreeSet<ItemStack> things = new TreeSet<>();
things.add(new ItemStack(Material.ACACIA_DOOR));
return things;
}
我也尝试在 TreeSet 中放置多个东西,它也不起作用。
现在我有了这个代码部分:
TreeSet<ItemStack> things = getItems();
如果我运行它,什么都不会发生。如果我用 try/catch 包围它,似乎会引发异常。 但如果我这样打印错误:
} catch (Exception exc) {
System.out.println("Catched an exception:")
exc.printStackTrace();
System.out.println(exc.getMessage());
System.out.println(exc);
}
没有任何错误/ Stacktrace 等出现。它只是说:
[INFO]: Catched an exception:
[WARN]: java.lang.ClassCastException
[INFO]: null
[INFO]: java.lang.ClassCastException
那么错误是什么,我该如何防止它以及为什么通过将带有 ItemSets 的 TreeSet 转换为带有 ItemSets 的 TreeSet 来得到它?
【问题讨论】:
-
ItemStack是否实现了Comparable<ItemStack>?我猜它不会。 -
@AndyTurner 我认为不是:公共类 ItemStack 扩展 Object 实现 Cloneable、ConfigurationSerializable
-
对,它没有。请注意,
extends Object也是不必要的。 -
你到底想做什么,@ScrouthTV?
-
至于为什么没有堆栈跟踪,this question 可能会解释为什么会发生这种情况(但我不确定)。
标签: java plugins minecraft bukkit