Snild
11/23/2017, 10:03 AMrw()
function is a stripped-down version of my original code (which had synchronized
instead of run
, and more complex code inside the while
block).
Why doesn't rw() compile? It seems the compiler can figure out that the return is there with run
or while(true)
separately, but not when combined. The same thing happens if you switch the while (true)
for an if (true)
.
It's possible to work around the problem with an extra return after the loop, but it doesn't look great, and the IDE warns about unreachable code. Also, in a function with a non-nullable return value, you may not have a valid object to return (maybe return null!!
would do?).
Anyway, does anyone have any idea? Is it a language limitation, a compiler bug, or am I just doing it wrong?