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

前端 未结 3 1760
忘了有多久
忘了有多久 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条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-01-18 11:25

    byte and short are the lesser memory consuming versions, and since intValue is abstract, the implementation of intValue can be used for the byte and short. I think that's why they should have done it like that.

提交回复
热议问题