I'm updating some code to use retrolambda on Android. The code mostly works, but the Android Studio 2.1 IDE seems to flag the previously OK code:
@WorkerThread void expensiveBackgroundOperation()
{
// Stuff.
}
@UiThread void updateSomeStuffOld()
{
AsyncTask.execute(new Runnable() {
@Override public void run()
{
expensiveBackgroundOperation();
}
});
}
@UiThread void updateSomeStuffNew()
{
AsyncTask.execute(() -> expensiveBackgroundOperation());
}
The following screenshot shows that the old runnable syntax is inferred correctly (or rather, it is not inferred and the run()
method would need to be annotated with @WorkerThread for annotations to work inside properly…) but in the retrolambda syntax version the method is inferred to run on the UI, which is not:
How can I annotate the lambda with a @WorkerThread
annotation? I've tried placing it in several places but I can't seem to make the IDE happy.