S.M_Emamian S.M_Emamian - 12 days ago 5
Android Question

How to convert Lambda into simple Java function expression

I don't want to use java

VERSION_1_8
in my module.
but in a snippet code from a library it using this code :

RxPaparazzo.takeImage(this)
.crop(options)
.size(size)
.usingGallery()
.subscribe(response -> {
if (response.resultCode() != Activity.RESULT_OK) {
response.targetUI().showUserCanceled();
return;
}

// Log.e("response",response.data());

response.targetUI().loadImage(response.data());
});


now how can I change it to simple java function expression ?

Answer

You can change it to anonymous class using the following trick in Android Studio

  1. Click on "->" or Get the cursor on "->"
  2. Press Alt + Enter (or Option + Return on Mac)
  3. Select Replace lambda with anonymous class.

Screenshot to explain:

Steps