Java got confused

all! this issue 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 explain why this code is not throwing an error when using "+ =" in eclipse. thank.

+3


source to share





All Articles