Say you have this code snippet
private final Set set = new HashSet() {{ add(1); }};
SomeConstructor() {
printSet();
}
long printSet() {
new Thread(() -> {System.out.println(set)}).start();
}
for example if the compiler decided to make this look like
private final Set set;
SomeConstructor() {
printSet();
set = new HashSet() {{ add(1); }};
}
this would be a problem because calculateWaitTime() makes a new Thread that might see the set as null or not having a 1 in it.
So the question again, is this reordering possible? Or do all final fields initialized outside of the constructor get initialized before the constructor or at least moved to the top of the constructor always by the compiler