Community
Participate
Working Groups
/* autoboxing in switch statement */ Byte no = 127; //warning: int boxed to Byte > fine switch(no) { //warning: Byte is unboxed into int > why in int??? output right? case -128: //error: cannot convert int to Byte > needs a explicit (byte)cast. break; case (byte)127: //works break; } no = new Byte(127) //also doesnt work without cast in jdt-compiler /* sun compiler doesnt need the explicit casts as it should be */
The second error in "new Byte(127)" is legite; there is no narrowing conversion on message invocations (dixit JLS 5.3)
There are indeed a few places where we do not allowing narrowing conversion before boxing (int (byte) cst assignmt compatible with Byte JLS5.2) Same issue for the following code which should be accepted. public class X { Byte foo() { final int i = -128; return i; } }
Added AutoboxingTest#test121-122.
Also there are autoboxing warnings emitted for case statement which aren't appropriate, since in the end no such conversion is performed. Should get rid of following line which is unnecessary in CaseStatement#resolveCase constantExpression.computeConversion(scope, caseType, switchExpressionType);
Created attachment 49349 [details] Proposed patch patch for 3.2 maintenance
Released for 3.2.1 [R3_2_maintenance] Released for 3.3M2 [HEAD] Fixed
Verified for 3.2.1 using build M20060908-1655
Verified for 3.3 M2 using build I20060918-0010.