public class Main {
public static void main(String[] args) {
A a =null;
try{
a = new A(1);
}catch (IOException e) {
System.out.println(a == null);
}
}
}
class A {
private int v;
public A(int val) throws IOException {
v= val;
throw new IOException("123");
}
}
as far as i know
the process of new a object has 3 steps:
1. allocate memory
2. execute construct function
3. assign to reference
due to instruction reordering of JIT, the process may be changed to 1->3->2 rather than 1->2->3.
so will the result of the code above always be true?
sorry for my english