-1

What is the use of Retrolambda?
Where do we use the Retrolambda framework?

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
Alis
  • 193
  • 1
  • 2
  • 10

2 Answers2

6

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.

Android Java 8 Support

Also, worth mentioning

Retrolambda lacks support for third party libraries that use Java 8 language features.

Tim
  • 41,901
  • 18
  • 127
  • 145
OneCricketeer
  • 179,855
  • 19
  • 132
  • 245
  • My point is that it isn't necessary to use it anymore. OP probably found some old tutorials that mention it – OneCricketeer Apr 28 '17 at 12:13
  • 4
    It 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 – Tim Apr 28 '17 at 12:18
  • Yeah, I rephrased. Thanks for the typo fixes – OneCricketeer Apr 28 '17 at 12:23
3

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

Jai Khambhayta
  • 4,198
  • 2
  • 22
  • 29