3

everyone! this problem is about Java cast behavior. Here is the code:

public static int dotProduct(double[] v1, double[] v2){
    //here the type of res is int
    int res = 0;
    for(int i=0; i<this.dimension; i++){
        res += v1[i] * v2[i];   // no errors
        res = res + v1[i] * v2[i];  // show cast errors
    }
    return res;
}

can someone explains why this code does not throw cast error when use "+=" in eclipse. thanks.

Zilong Wen
  • 31
  • 1

0 Answers0