Geoff Berry wrote:
> Vincent GAY-PARA <[EMAIL PROTECTED]> writes:
>
> > Hi,
> >
> > At DMS we tried to compile GNU Classpath with KJC
> > (http://www.dms.at/kjc) and we encoutered some problems.
> >
> > ObjectInputStream:
> > ==================
> > problem with an expression (java/io/ObjectInputStream.java:1188:
> > Variable "value" cannot be initialized by a value of type "int" [JLS
> > 4.5.4])
> > Which compiler do you use ???
> > please rewrite:
> > char value = default_initialize ? 0 : this.realInputStream.readChar
> > ();
> > as:
> > char value = default_initialize ? (char)0 :
> > this.realInputStream.readChar ();
> >
> > see also: java/io/ObjectInputStream.java:1223: Variable "value" cannot
> > be initialized by a value of type "int" [JLS 4.5.4]
>
>
> I believe this is a compiler error, not an error in the code. `value'
> is not being initialized with a value of type int, but with a value of
> type char. JLS 15.24:
>
> The type of a conditional expression is determined as follows:
>
> ...
>
> Otherwise, if the second and third operands have numeric type,
> then there are several cases:
>
> ...
>
> If one of the operands is of type T where T is byte, short, or
> char, and the other operand is a constant expression of type
> int whose value is representable in type T, then the type of
> the conditional expression is T.
You're right.
I've corrected KJC accordingly.
My test case was:
short s = aCondition ? 0 : 1; // compile time error
but the following is valid:
short s = aCondition ? 0 : (short)1;
Sorry for the inconvenience.
Vincent for DMS
>
>
> ...
>
> --
> Geoff Berry