Name: ngR10089 Date: 02/11/2004
The latest spec "Autoboxing and Auto-Unboxing support for the Javatm
Programming Language" says about the type of the prefix/postfix
decrement/increment expressions:
JLS 15.14.1 Postfix Increment Operator ++
"The type of the postfix increment expression is the type of the variable "
JLS 15.14.2 Postfix Decrement Operator --
"The type of the postfix decrement expression is the type of the variable."
JLS 15.15.1 Prefix Increment Operator ++
"The type of the prefix increment expression is the type of the variable."
JLS 15.15.2 Prefix Decrement Operator --
"The type of the prefix decrement expression is the type of the variable."
javac (jdk1.5.0-b37) successfully compiles test below.
The test execution shows that the type of the prefix/postfix
decrement/increment expressions is not the type of the variable.
> java -version
java version "1.5.0-beta2"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0-beta2-b37)
Java HotSpot(TM) Client VM (build 1.5.0-beta2-b37, mixed mode)
> javac -d . -source 1.5 test.java
> java -Xfuture p.test
Character 2 12
Byte 0 10
Short 1 11
Integer 3 13
Long 4 14
Float 5 15
Double 6 16
>
----------------- test.java -----------------
package p;
public class test {
static final int byte_t = 0;
static final int short_t = 1;
static final int char_t = 2;
static final int int_t = 3;
static final int long_t = 4;
static final int float_t = 5;
static final int double_t = 6;
static final int Byte_t = 10;
static final int Short_t = 11;
static final int Character_t = 12;
static final int Integer_t = 13;
static final int Long_t = 14;
static final int Float_t = 15;
static final int Double_t = 16;
static int getType(byte b) {
return byte_t;
}
static int getType(short s) {
return short_t;
}
static int getType(char c) {
return char_t;
}
static int getType(int i) {
return int_t;
}
static int getType(long l) {
return long_t;
}
static int getType(float f) {
return float_t;
}
static int getType(double d) {
return double_t;
}
static int getType(Byte b) {
return Byte_t;
}
static int getType(Short s) {
return Short_t;
}
static int getType(Character c) {
return Character_t;
}
static int getType(Integer i) {
return Integer_t;
}
static int getType(Long l) {
return Long_t;
}
static int getType(Float f) {
return Float_t;
}
static int getType(Double d) {
return Double_t;
}
public static void main(String argv[]) {
Character c1 = new Character((char)2);
Byte b1 = new Byte((byte)3);
Short s1 = new Short((short)4);
Integer i1 = new Integer(5);
Long l1 = new Long(6);
Float f1 = new Float(7);
Double d1 = new Double(8);
System.out.println("Character "+getType(c1++)+" "+getType(c1));
System.out.println("Byte "+getType(b1--)+" "+getType(b1));
System.out.println("Short "+getType(++s1)+" "+getType(s1));
System.out.println("Integer "+getType(--i1)+" "+getType(i1));
System.out.println("Long "+getType(l1++)+" "+getType(l1));
System.out.println("Float "+getType(f1--)+" "+getType(f1));
System.out.println("Double "+getType(++d1)+" "+getType(d1));
}
}
---------------------------------------------
The JCK tests
lang/EXPR/expr182/expr18208/expr18208.html
lang/EXPR/expr190/expr19008/expr19008.html
lang/EXPR/expr205/expr20510/expr20510.html
lang/EXPR/expr213/expr21308/expr21308.html
fail due to this bug.
======================================================================
- duplicates
-
JDK-4980014 incorrect type for compound assignment to wrapper type
-
- Resolved
-