Bug 36857 - Using the operator += with a String on the right side results in a compile error.
Summary: Using the operator += with a String on the right side results in a compile er...
Status: RESOLVED INVALID
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 2.1   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 3.0 M1   Edit
Assignee: JDT-Core-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2003-04-24 13:25 EDT by Robert Baccus CLA
Modified: 2003-06-02 06:13 EDT (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Robert Baccus CLA 2003-04-24 13:25:06 EDT
The following code segment will fail to compile using the Eclipse JDT.

	int[] intArray;
	Object[] oa = hash.keySet().toArray();
	Arrays.sort(oa); // mmmmm, Java.util.Arrays 
	for (int i=0; i< oa.length; i++) {
	    intArray=(int[])hash.get(oa[i]);
	    int rowTotal = intArray[0] + intArray[1] + intArray[2];
	    while (((String) oa[i]).length() < 4) { // pad w/ leading '0's as 
needed
		oa[i]= "0" + oa[i];
	    }
FAILS	    oa[i] += "     |   " + rowTotal + "   |";
	    for (int j=0; j<intArray.length-1; j++) {
FAILS		oa[i] += "     " + intArray[j] + "    ";
	    }
FAILS	    oa[i] += "|     " + intArray[intArray.length-1] + "/" + (rowTotal-
intArray[intArray.length-1]);
	    System.out.println(oa[i]);
	}
	System.out.println();
    }

The error message is 
"The operator += is undefined for the argument type(s) Object, String"


When compiled using ANT with JDK1.4.1_02 this compiles and runs without errors.
Comment 1 Olivier Thomann CLA 2003-04-24 16:02:33 EDT
This is a bug in javac 1.4.1_02 which has been fixed in 1.4.2_b19.

D:\temp>java -version
java version "1.4.2-beta"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2-beta-b19)
Java HotSpot(TM) Client VM (build 1.4.2-beta-b19, mixed mode)

D:\temp>javac X1.java
X1.java:17: incompatible types
found   : java.lang.Object
required: java.lang.String
                        oa[i] += "     |   " + rowTotal + "   |";
                          ^
X1.java:19: incompatible types
found   : java.lang.Object
required: java.lang.String
                                oa[i] += "     " + intArray[j] + "    ";
                                  ^
X1.java:21: incompatible types
found   : java.lang.Object
required: java.lang.String
                        oa[i] += "|     "
                          ^
3 errors

See http://developer.java.sun.com/developer/bugParade/bugs/4642850.html for
further reference.

Closed as INVALID.