Im using android studio and I want to use lambda expression that are available only from java 8, and when I try to use it I get:
Lambda expression are not supported at this language level.
So, how can I change that on AndroidStudio?
Android does not support Java 8. It only supports up to Java 7 (if you have kitkat) and still it doesn't have invokedynamic, only the new syntax sugar. If you want to use lambdas, one of the major features of Java 8 in Android, you can use gradle-retrolamba.
Get the stream of elements in which the duplicates are to be found. For each element in the stream, count the frequency of each element, using Collections. frequency() method. Then for each element in the collection list, if the frequency of any element is more than one, then this element is a duplicate element.
Using Java 8 Stream. You can use the distinct() method from the Stream API. The distinct() method return a new Stream without duplicates elements based on the result returned by equals() method, which can be used for further processing.
So, how can I change that on AndroidStudio?
you can't. Android supports up to java 7. If you want to use AS only for Lambda, you can use gradle-retrolamba or retrolambda, which back-port retrolambda on java 6/7
Android supports Java 6 up to KitKat (4.4) with some minor syntactic sugar (like diamond operator), and Java 7 from there on (Lollipop and Marshmallow atm). Lambdas and other Java 8 stuff are available only as plugins (e. g. gradle-retrolambda or the original retrolambda). They will probably be included in API at some point in time (like Java 7 and KitKat), but it doesn't seem likely it'll be very soon.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With