java.util.concurrent.TimeUnit
有这个来源:
public long convert(long sourceDuration, TimeUnit sourceUnit) {
throw new AbstractMethodError();
}
为什么这不是像
这样的abstract
方法
abstract int excessNanos(long d, long m);
答案 0 :(得分:6)
方法声明上方的单行注释说明如下,
// 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
是错误ID,
JDK-6287639:枚举类中的抽象方法不应列为抽象
现在考虑以下enum
将其视为类,将每个枚举常量视为Object
,很明显,如果我们创建一些抽象的Object
,我们必须提供实现并避免此convert
不是abstract
,
enum Blocks {
A1, B1, C1;
// It will say enum constant must implement
// the abstract method test
abstract int test();
}