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
java casting


source to share


No one has answered this question yet

See similar questions:

nineteen
Is it valid to compare double to int in java?
nine
implicit conversion to java operator + =

or similar:

6170
Is Java "pass-by-reference" or "pass-by-value"?
3799
How do I read / convert an InputStream to a string in Java?
3486
Why Java + =, - =, * =, / = assignment operators don't require casting?
3044
Making a memory leak with Java
2964
How to cast int to enum?
2727
What is serialVersionUID and why should I use it?
2296
Output malloc result?
1510
Regular casting vs. static_cast vs. dynamic_cast
935
Eclipse Cannot Start - Java was started but exit code returned = 13
573
How do I address unverified throw warnings?



All Articles
Loading...
X
Show
Funny
Dev
Pics