簡體   English   中英

為什么java.util.concurrent.TimeUnit.convert拋出AbstractMethodError而不是抽象

[英]Why does java.util.concurrent.TimeUnit.convert throw an AbstractMethodError instead of being abstract

java.util.concurrent.TimeUnit有這個來源:

public long convert(long sourceDuration, TimeUnit sourceUnit) {
    throw new AbstractMethodError();
}

為什么這不是一個abstract方法

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:枚舉類中的抽象方法不應列為抽象方法

現在考慮以下enum將其視為類和每個枚舉常量作為Object ,很明顯,如果我們創建一些抽象的Object ,我們必須提供實現並避免這種convert不是abstract

enum Blocks {
    A1, B1, C1;
    // It will say enum constant must implement 
    // the abstract method test
    abstract int test();
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM