6

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 ?

2 Answers 2

35

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

Sign up to request clarification or add additional context in comments.

Comments

1

it should be some thing along the line of the following.

   RxPaparazzo.takeImage(this)
        .crop(options)
        .size(size)
        .usingGallery()
        .subscribe(new _ON_CALLBACK_LISTENER ()
        {
            @Override
            void _ON_CALLBACK (_FIELD_TYPE response){
                if (response.resultCode() != Activity.RESULT_OK) {
                    response.targetUI().showUserCanceled();
                    return;
                }

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

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

you need to know the listenerType (_ON_CALLBACK_LISTENER) and also the parameterType (_FIELD_TYPE)

just hover over the codes, and there should be some hints, and Alt-Enter may auto generate the code stubs for you.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.