Why shortValue() method are concrete but intValue() is abstract into java.lang.Number?

前端 未结 3 1774
忘了有多久
忘了有多久 2021-01-18 10:33

I have read source code of java.lang.Number and I wondered why

  1. intValue()
  2. longValue()
  3. floatVa
3条回答
  •  长发绾君心
    2021-01-18 11:24

    According to the documentation of the Number class, the methods byteValue and shortValue were added first in JDK1.1. This is unlike the other "Value" methods which were already available in the very first JDK release. My assumption is that those two methods were made concrete in order to keep compatibility with existing (also non-standard) subclasses of Number, which would otherwise have been broken by the addition of new abstract methods in the superclass.

提交回复
热议问题