java.lang.Number doesn't implement “+” or any other operators?

后端 未结 7 1728
梦毁少年i
梦毁少年i 2020-12-17 19:56

I\'m creating a class which is supposed to be able to be used with an array of any type of number (float, int, etc), so here is one method I have:

// T exten         


        
7条回答
  •  悲哀的现实
    2020-12-17 20:34

    Since every possible byte, short, char, int, float, double can be represented as a double its is much more efficient (as its a primitive instead of any object) and simpler to use double instead of Number You would need specific types if you need long accurately or BigDecimal or BigInteger.

提交回复
热议问题