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

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

    I think this is what you want

    public synchronized average() {  
        double ret = new double[queue[0].length];  
        for (int i = 0; i < ret.length; ++i) {  
            for (int j = 0; j < size; ++j) {  
                ret[i] += queue[j][i];  
            }  
            ret[i] /= size;  
        }  
        return ret;  
    }
    

提交回复
热议问题