Java Generics and adding numbers together

前端 未结 7 1802
没有蜡笔的小新
没有蜡笔的小新 2020-11-27 07:58

I would like to generically add numbers in java. I\'m running into difficulty because the Numbers class doesn\'t really support what I want to do. What I\'ve tried so far

相关标签:
7条回答
  • 2020-11-27 08:38

    As Number class does not expose interface for performing calculations, the only way to solve this problem is to create classes which encapsulates required operations for each supported numeric type. Than in your class you will need to use specific type.

    0 讨论(0)
提交回复
热议问题