I have a problem with the following Java code

Posted by Sanjeev on Stack Overflow See other posts from Stack Overflow or by Sanjeev
Published on 2010-03-21T05:49:38Z Indexed on 2010/03/21 6:21 UTC
Read the original article Hit count: 253

Filed under:
public class b {
    public static void main(String[] args) {
        byte b = 1;
        long l = 127;
    //  b = b + l;            // 1 if I try this then it does not compile
        b += l;               // 2 if I try this then it does     compile
        System.out.println(b);  
    }
}

I am using this code but I have problem: I don't understand why b=b+l; is not compiling but if I write b+=l; then it compiles and runs.

Please explain why this happens.

© Stack Overflow or respective owner

Related posts about java