java.util.concurrent.TimeUnit
有这个来源:
public long convert(long sourceDuration, TimeUnit sourceUnit) {
throw new AbstractMethodError();
}
为什么这不是一个抽象
方法
abstract int excessNanos(long d, long m);
最佳答案
方法声明上方的单行注释如下,
// To maintain full signature compatibility with 1.5, and to improve the
// clarity of the generated javadoc (see 6287639: Abstract methods in
// enum classes should not be listed as abstract), method convert
// etc. are not declared abstract but otherwise act as abstract methods.
在这里,6287639
是 bug id,它说,
JDK-6287639 : Abstract methods in enum classes should not be listed as abstract
现在考虑下面的 enum
,将其视为类,并将每个枚举常量视为 Object
,很明显,如果我们创建 Object
一些抽象的东西我们必须提供实现并避免这种convert
不是abstract
,
enum Blocks {
A1, B1, C1;
// It will say enum constant must implement
// the abstract method test
abstract int test();
}
关于java - 为什么 java.util.concurrent.TimeUnit.convert 抛出 AbstractMethodError 而不是抽象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36762450/