title: use of the += operator
body: <p>I have a question about the operators += and =.</p>
  
  <p>In the following code you can clearly see that there is a difference between the operations</p>
  
  <pre><code>sum+=n
  </code></pre>
  
  <p>and</p>
  
  <pre><code>sum=sum+n
  </code></pre>
  
  <p>Which are known to be equivalent.</p>
  
  <p>This doesn't compile without casting</p>
  
  <pre><code>this.mix = mix + col;
  </code></pre>
  
  <p>This compiles. Why?</p>
  
  <pre><code>this.mix += col;
  </code></pre>
  
  <p>Please refer to the addToMix method: </p>
  
  <pre><code>public class Color {
      byte r;
      byte g;
      byte b;
      byte mid;
      byte mix;
  
      public Color (byte r, byte g, byte b) {
          this.r = r;
          this.g = g;
          this.b = b;
          createMid(r, g);
      }
  
      private void createMid(byte r, byte g) {
          this.mid = (byte)(r + g);
          createMix(r,g);
      }
  
      private void createMix (byte mid, byte b) {
          this.mix = (byte)(mid + b);
      }
  
      public void addToMix (byte col) {
          //this.mix = mix + col; // not compiled without casting obviously
          this.mix += col; // compiled. why?
      }
  
      public byte getMid() {      
          return this.mid;
      }
  
      public byte getMix() {      
          return this.mix;
      }   
  }
  </code></pre>