Kotlin Extension Functions suddenly require api level 24

前端 未结 2 770
北海茫月
北海茫月 2020-12-10 11:45

I just noticed this lint error:

Call requires API Level 24 (current min is 19) java.util.map#foreach

when I use the extension fu

相关标签:
2条回答
  • 2020-12-10 12:19

    What you are using is not kotlin.collections.MutableMap.forEach.

    What you are using seems to be Map.forEach in Java 8.

    Read this article: http://blog.danlew.net/2017/03/16/kotlin-puzzler-whose-line-is-it-anyways/

    This seems to be a common mistake.

    Java 8 is well-supported from Android API level 24.

    For short, do not use like map.forEach { t, u -> Log.i("tag", t + u) }.
    Use like map.forEach { (t, u) -> Log.i("tag", t + u) }.
    (Not two parameters. Just one parameter which is a pair.)

    0 讨论(0)
  • 2020-12-10 12:24

    Map.forEach is supported in Java 8 and its support in Android started from API 24

    0 讨论(0)
提交回复
热议问题