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

后端 未结 7 1735
梦毁少年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:10

    Sadly, you can't. Arithmetic operators work only on primitive types (and thanks to autoboxing and autounboxing on their wrappers). You have to override the given method for all the primitive types that you require the method to work on, as is done in many JDK classes.

提交回复
热议问题