You can run runnables. Obviously, the equivalent of blocks will require lambdas, which come in Java 8, but who knows how long Android has been supporting them (they still use JUnit 3.8).
There are many places in Android where things like blocks are done, for example:
this.currentConditionsActivity.runOnUiThread(new Runnable() { @Override public void run() { currentConditionsActivity.onLocationChanged(...); } }); instrumentation.waitForIdleSync(); setupViewElements();
As you can see, you need to instantiate an anonymous class, but in most IDEs the stupidity of the template is facilitated by autocompletion. This was done in Android Studio, and it all happened after executing the new Runnable () (and if you dump the code, it even shows a syntax similar to what lambdas will have).
So the state is for now. Not so bad many do it ...
Rob
source share