Is it possible to write a generic +1 method for numeric box types in Java?

后端 未结 7 2036
旧巷少年郎
旧巷少年郎 2021-01-18 15:56

This is NOT homework.

Part 1

Is it possible to write a generic method, something like this:



        
7条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-01-18 16:17

    Not all of the subclasses of Number can be autounboxed. BigDecimal, for instance, can't be autounboxed. Therefore the "+" operator won't work for it.

提交回复
热议问题