Answer the question
In order to leave comments, you need to log in
Explain Java code?
There is the following code:
int a = 1, b = 2;
b=a + 0*(a=b);
System.out.println(b+" " +a);
Answer the question
In order to leave comments, you need to log in
Here's what happens after compilation:
//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//
public class test {
public test() {
}
public static void main(String[] args) {
byte a = 1;
byte b = 2;
byte var10000 = a;
a = b;
int b1 = var10000 + 0 * b;
System.out.println(b1 + " " + a);
}
}
presumably this is an example of undefined behavior.
terrible magic, which, when applied in production, will spoil the healthy sleep of the developer.
the java compiler, as shown in one of the answers, added a temporary variable, which provided this behavior.
For example, if you draw this example in C (gcc), there will be no such magic. Again, I guess another compiler might do otherwise.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question