Classic method throwing AbstractMethodError VS abstract method
I just had a look on the TimeUnit enum source code (simplified herebelow):
public enum TimeUnit {
SECONDS {
public long toMillis(long d) { return d * 1000L; }
},
MINUTES {
public long toMillis(long d) { return d * 10000L; }
};
public long toMillis(long duration) {
throw new AbstractMethodError();
}
}
They could also have implemented it using an abstract method:
public enum TimeUnit {
SECONDS {...}, MINUTES {...};
public abstract long toMillis(long duration);
}
Since they chose the first implementation, I guess there must be a reason
why. Thus, my question is: why? Can the AbstractMethodError be ever
thrown? If yes, in which case(s)?
No comments:
Post a Comment