Reputation: 2030
Please help me to understand how following code is working?
int i = (byte) +(char) -(int) +(long) -1;
Upvotes: 0
Views: 40
Reputation: 7001
final long longValue = +(long) -1;
final int intValue = -(int) longValue;
final int charValue = +(char) intValue;
final int byteValue = (byte) charValue;
System.out.printf("%s %s %s %s%n", longValue, intValue, charValue, byteValue);
Output:
-1 1 1 1
-1
1
1
1
So the end result is 1
Upvotes: 3