2

This is rly strange. In official documetation library retrolambda we can read just put this into own gradle:

buildscript {
   repositories {
      mavenCentral()
   }

   dependencies {
      classpath 'me.tatarka:gradle-retrolambda:3.7.0'
   }
}

// Required because retrolambda is on maven central
repositories {
   mavenCentral()
}

apply plugin: 'com.android.application' //or apply plugin: 'java'
apply plugin: 'me.tatarka.retrolambda'

but now when I'm trying to write something with lambda:

btnLogin.setOnClickListener(view -> btnLogin.setVisibility(View.INVISIBLE));

I got from AndroidStudio:

Lambda expression are not supported at language level 1.7

Of course I can set in my build

compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

but this is no sense, now with 1.8 I don't need RetroLambda :)

So question is How to use lambda with Java 1.7 ?

companyn2
  • 85
  • 1
  • 9
  • 1
    so what is Retrolambda ? – companyn2 Jun 15 '18 at 14:59
  • 3
    @companyn2 A hack that should no longer be used. It shouldn't have been used before either. If you need lambdas, use Java 8. If you need to use Java 7, don't use lambdas, use annonymous classes. Given that backwards compatibility is darn near 100%, there's no reason to continue to use Java 7 for anything new. – Gabe Sechan Jun 15 '18 at 14:59
  • It changes the bytecode. Not the code that you write. https://github.com/orfjackal/retrolambda/blob/master/README.md – ifly6 Jun 15 '18 at 14:59
  • 2
    @companyn2 It allows lambdas to *run* on Java 6 and 7, by expanding lambdas into statements earlier JVMs can understand. You still need Java 8 to write the lambdas, but don't need Java 8 to run the code. – Michael Dodd Jun 15 '18 at 15:00
  • 1
    why just not to remove retrolambda and use Android Studio 3.0 or higher? – Andrey Danilov Jun 15 '18 at 15:18

0 Answers0