Is there a way to use Java 8 functional interfaces on Android API below 24?

前端 未结 4 1277
梦如初夏
梦如初夏 2021-01-01 10:26

I can use retrolambda to enable lambdas with Android API level <24. So this works

myButton.setOnClickListener(view -> Timber.d(\"Lambdas work!\"));
         


        
4条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-01-01 11:16

    For alternative, Lightweight-Stream-API also provides backport support. Like android-retrostreams metioned above, you have to replace some package names by using:

    com.annimon.stream.function instead of java.util.function

    com.annimon.stream.ComparatorCompat instead of java.util.Comparator

提交回复
热议问题