Android Studio refactor revert all lambdas and other Java 8 features

Olexii Muraviov :

I have an Android library project with

 compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

It uses a lot of lambdas, try with resources and etc.

How could I downgrade sourceCompatibility & targetCompatibility to Java 1.6 instead?

Is there such functionality built in Android Studio IDE?

Chris Stillwell :

You can replace the lambda by placing the cursor inside the -> and pressing Alt + Enter then select "Replace lambda with..."

enter image description here


You can do it on an entire file by expanding the menu and selecting "Fix all..."

enter image description here


You can do it on the whole project by following the above steps, but instead click "Run inspection on..."

enter image description here

Select "Whole project"

enter image description here

Once the inspection finishes, right click on the "Lambda can be replaced..." section and select "Replace lambda with..."

enter image description here

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=436918&siteId=1