input line is too long

Eric Benjamin Blake ebb9@email.byu.edu
Thu Jan 2 16:38:00 GMT 2003


GCJ does have a bug, not jikes.

> Erik Poupaert wrote:
> > (3) This is the (short) to (char) cast stuff:
> > 
> > src/org/eclipse/swt/widgets/Control.java:46://X static final short []
> > ACCENTS = new short [] {'~', '`','\'', '^', '"'};
> > 
> > I had to change it into: "static final short [] ACCENTS = new short []
> > {(short)'~', (short)'`', (short)'\'',(short) '^',(short) '"'};"
> > 
> > Same for: src/org/eclipse/swt/widgets/Decorations.java:320: accel.key =
> > (short) 'Q'; //X
> 
> IMHO GCJ is doing the right thing. See:
> 
> http://java.sun.com/docs/books/jls/second_edition/html/conversions.doc.html#184206
> 
> And I quote from there:
> ----------------------------------- 8< -----------------------------------
> The following test, however, produces compile-time errors:
> 
> class Test {
> 	public static void main(String[] args) {
> 		short s = 123;
> 		char c = s;			// error: would require cast
> 		s = c;				// error: would require cast
> 	}
> }
> 
> because not all short values are char values, and neither are all char values short values.
> ----------------------------------- 8< -----------------------------------

You missed the section on assignment conversions. Gcj is still following the 1st
edition rules, but javac and jikes follow the 2nd edition rules. An assignment
conversion context (assignments, switch statement constants, and array
initializations as in the example) is legal if the value is a compile-time
constant and fits within the target type.  The Jacks test suite has several
tests for these rules; it IS legal to assign a CONSTANT char to a short,
provided the char is between 0 and 0x7fff inclusive.

--
Eric Blake



More information about the Java mailing list