Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert Lambda into simple Java function expression

Tags:

android

lambda

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 ?

like image 874
S.M_Emamian Avatar asked Nov 27 '16 07:11

S.M_Emamian


People also ask

How do you replace lambda expression with method reference?

If you are using a lambda expression as an anonymous function but not doing anything with the argument passed, you can replace lambda expression with method reference. In the first two cases, the method reference is equivalent to lambda expression that supplies the parameters of the method e.g. System.


1 Answers

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

like image 66
Akshay Chordiya Avatar answered Oct 05 '22 13:10

Akshay Chordiya