Why java.util.concurrent.TimeUnit.convert throws an AbstractMethodError instead of an abstract

java.util.concurrent.TimeUnit has this source:

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

Why is this not such an abstract method as

 abstract int excessNanos(long d, long m); 
+6
source share
1 answer

Single comments on the method declaration say the following:

 // 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. 

Here 6287639 is the error identifier that says:

JDK-6287639: abstract methods in enumeration classes should not be listed as abstract

Now consider the following enum , treating it as a class and each enum constant as Object , it is clear that if we create an Object something abstract, we must provide an implementation and avoid this convert not abstract .

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

All Articles