Using the Retrolambda framework (to support some of the java8 features),

faced with such a problem, some functions related to references to methods work only with api24 and more. For example:

Function<Double, Double> Sqr = val -> val * val; textView.setText("Square: " + Double.toString(Sqr.apply(2.0)) ); 

the Sqr.apply(2.0) compiler emphasizes and says that you need a minimum api24 (I have a minimum of api15).

Another example:

  Consumer<Integer> fun1 = Person::increaseScore; fun1.accept(12); 

accept(12); method accept(12); The same mistake is underlined.

Is this something I incorrectly configured in Retrolambda or the above things can really be performed only for android version api24 and higher?

Thank.

    2 answers 2

    List of backportit retrolambda

    There is not a word about adding new methods to the old API.

    Lambda expressions are backported by converting to anonymous inner classes. This is a list of stateless lambda expressions to avoid repeated object allocation.

    Method references are basically just syntax sugar for lambda expressions and they are backported in the same way.

    If you would like to go through the rules, you’ll like it. configurable.

    Objects.requireNonNull calls to JDK 9, you can replace it with JDK 9 use Objects.requireNonNull, JDK version used Object.getClass.

    Optionally also:

    There are no methods for the companion class (interface name + "$") .

    There are a number of ways to change the interface.

    And a separate item

    Known limits

    Does not backport Java 8 APIs.

    • Thanks, it turns out essentially retrolyambda does not support Consumer, apply, and so on. - foxis

    Make sure that all the classes that you use are imported from com.annimon.stream.function and not from java.util.function , these classes are called the same and often there is confusion

    java.util.function - belong to the eighth java, and are not available until api24 com.annimon.stream.function is, sobsna, retrorolamda.

    ADDITIONALLY

    If you don’t want to keep track of what you import each time, then exclude from auto-import those classes that have the same name as the retro-league classes. To do this, go to File-> Settings-> Editor-> General-> Auto import. There you will find the section Exclude from import and Completion. There you can add, for example, java.util.function.Function so that you never confuse it with com.annimon.stream.function.Function

    • Thanks, only com.annimon.stream.function.Function is another framework as I understand it, not retrolambda. - foxis
    • one
      Yes, there was confusion, retrolumbad and annimon are two different things. The Annimon Stream just doesn’t work without the retrolumbad, so they sometimes mix in my head. Use github.com/aNNiMON/Lightweight-Stream-API in conjunction with retroballmda and you can use both Consumer and Function and other goodies - P. Ilyin
    • Well, I will try, thanks a lot. - foxis