Java I ++ traps, java I traps
Interview traps:
Int I = 0; I = I ++;
At this time, the I value:
I is eventually 0;
When I = I ++ is executed, the priority of the value assignment symbol is the lowest. I ++ is first executed;
Execute I ++. The program first writes the I value 0 into the stack, and then performs operations on I ++;
After I ++, I is 1;
Finally, execute a value assignment to bring up the DATA 0 in the stack, assign the value to I, and then set the value to 0 again;
Therefore, best practice 1: Do not assign values to the same variable more than once in a single expression.
Java traps? Answer
1. It should be Type Mismatch
True/false is a boolean type, which is a basic data type. null generally refers to a null object, so an error is returned.
Here is an example:
Int a = null (error Reported)
Integer a = null (correct)
2. You can switch to this mode.
Fun (I = 0? Boolean. TRUE: (I = 1? Boolean. FALSE: null ))
Boolean. TRUE/Boolean. FALSE indicates the object.
3. Check the source code.
Public static final Boolean FALSE = new Boolean (false );
Public static final Boolean TRUE = new Boolean (true );
I ++ problems in JAVA?
JAVA and C ++ have different processing operations on the ++ operator. JAVA copies an I value in the memory before performing operations, while C ++ directly performs operations on the original value.
In java, the essence of the I = I ++ operation is to execute I = I first and then copy an I copy in the memory to its ++, So I is 0
In C ++, I = I is first executed. At this time, I is 0 and then I ++ is executed. At this time, I is 1, so 1 is output.