I know this is an old thread, but what about this? I find it more readable than the Koraktor and AlexR versions.
Object obj = null; for (obj=getObject(); obj==null; obj=getObject()) { Thread.sleep(25); } obj.toString();
But in my code, I usually enable "Enable" assert "in zero analysis in the eclipse compiler settings and add assert. Therefore, I do not need to change the control flow and at the same time avoid the warning:
Object obj = null; while (true) { obj = getObject(); if (obj != null) break; Thread.sleep(25); } assert obj!=null; obj.toString();
source share