Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-6369051

javac cannot handle += operator correctly in Genericized code

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P4 P4
    • None
    • 5.0
    • tools
    • sparc
    • solaris_10

      FULL PRODUCT VERSION :
      java version "1.5.0_06"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_06-b05)
      Java HotSpot(TM) Server VM (build 1.5.0_06-b05, mixed mode)


      ADDITIONAL OS VERSION INFORMATION :
      SunOS Generic_118822-01 sun4u sparc SUNW,Sun-Fire-880

      A DESCRIPTION OF THE PROBLEM :
      Comiling the code below produces an error at the statement "value += 1;",
      although no error with the equivalent statement "value = value + 1;"

      Value.java:8: operator + cannot be applied to java.lang.Object,int
      value += 1;
                    ^



      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
        To compile the source code below with javac.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      It should be compiled without an error.
      ACTUAL -
      Value.java:8: operator + cannot be applied to java.lang.Object,int
      value += 1;
                    ^

      ERROR MESSAGES/STACK TRACES THAT OCCUR :
      Value.java:8: operator + cannot be applied to java.lang.Object,int
      value += 1;
                    ^

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      public class Value<T> {
          public T value;
      }

      class IntegerValue extends Value<Integer> {
          void increment() {
      value = value + 1;
      value += 1;
          }
      }
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      Do not use += operator.

            Unassigned Unassigned
            ndcosta Nelson Dcosta (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: