Possible Duplicate:
Weird java behavior with casts to primitive types
Let’s look at the following code snippet in Java.
package typecasting;
final public class TypeCasting
{
public static void main(String[] args)
{
int i = (byte) + (char) - (int) + (long) - 1;
System.out.print("\n i = "+i+"\n");
}
}
The statement System.out.print("\n i = "+i+"\n"); displays i = 1. How?
This code uses the unary
+and-operators.It’s equivalent to
-(-1)with a bunch of extra casts. (the unary+operator doesn’t change the value)