What is the use of Retrolambda?
Where do we use the Retrolambda framework?
-
1It's to be able to use Java 8's lambda functionality into Android. You'd use it if you want to use lamdbas– Ken WolfApr 28, 2017 at 11:32
-
what is backport ?– AlisApr 28, 2017 at 11:32
-
I've edited my comment– Ken WolfApr 28, 2017 at 11:33
-
1Wherever you want to use lamdbas– Ken WolfApr 28, 2017 at 11:41
-
1stackoverflow.com/a/30752800/833647– Ken WolfApr 28, 2017 at 11:43
2 Answers
In earlier versions of Android, Java 8 was not supported. Retrolambda provides a way to use "lambda expressions" on Java versions below 8.
Common examples of lambdas in Android are for click listeners
button.onClick(v -> Log.i("hello", "lambdas"));
However, as of Android Studio 2.4 Preview 4 and later, it
supports all Java 7 language features and a subset of Java 8 language features
"Lambdas" are available on all SDK versions
Android studio provides tooling to migrate from Retrolambda as it is no longer necessary.
Also, worth mentioning
Retrolambda lacks support for third party libraries that use Java 8 language features.
-
My point is that it isn't necessary to use it anymore. OP probably found some old tutorials that mention it Apr 28, 2017 at 12:13
-
4It is necessary for everybody who wants to use lambdas and not develop with preview builds of AS. Anyway suggesting someone should use B where the question is asking what A is used for probably belongs in a comment– TimApr 28, 2017 at 12:18
-
Retrolambda is a library which allows to use Java 8 lambda expressions, method references and try-with-resources statements on Java 7, 6 or 5.
The Gradle Retrolambda Plug-in allows to integrate Retrolambda into a Gradle based build. This allows for example to use these constructs in an Android application, as standard Android development currently does not yet support Java 8.
TextView textView = (TextView) findViewById(R.id.text_view);
textView.setOnLongClickListener(v -> System.out.println("Long Click"));
you can use this link : https://mayojava.github.io/android/java/using-java8-lambda-expressions-in-android
-
1That link is outdated as Java 8 features are in the Android Studio canary channel. Without Jack compiler Apr 28, 2017 at 12:03