It's possible to add the volatile modifier to a field that is private and static?
Example Code
// I don't know when test is initalized
public class Test {
private static String secretString;
public Test() {
secretString = "random";
}
}
public class ReflectionTest extends Thread {
public void run() {
Class<?> testClass = Class.forName("Test");
Field testField = testClass.getDeclaredField("secretString");
while (testField.get(null) == null) {
// Sleep, i don't know when test is initalized
// When it'is i need the String value
// But this loop never end.
}
}
}
I think that if i set the field volatile the loop end without any problem