How to use lambda in Android Studio?

First of all, add following to build.gradle(app) file:

android {
    defaultConfig {
        jackOptions {
            enabled true
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8

After that you can use lambda in your application:

        Button button = (Button) findViewById(;
        button.setOnClickListener(v-> Toast.makeText(getApplicationContext(), "Hello Lambda", Toast.LENGTH_LONG).show());

instead of this:

        button.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                Toast.makeText(getApplicationContext(), "Hello Lambda", Toast.LENGTH_LONG).show();