我刚刚注意到了这个线头错误:
Call requires API Level 24 (current min is 19) java.util.map#foreach
当我在Kotlin中的MutableMap上使用扩展函数for Each时. 这在我写这行的时候还没有发生,但是现在就在那里了. 我在我的另一台机器上没有看到这个错误.
我刚刚注意到了这个线头错误:
Call requires API Level 24 (current min is 19) java.util.map#foreach
当我在Kotlin中的MutableMap上使用扩展函数for Each时. 这在我写这行的时候还没有发生,但是现在就在那里了. 我在我的另一台机器上没有看到这个错误.
您使用的不是kotlin.collections.MutableMap.forEach
.
What you are using seems to be Map.forEach
in Java 8.
Refer to this article: http://blog.danlew.net/2017/03/16/kotlin-puzzler-whose-line-is-it-anyways/
This seems to be a common mistake.
Java8受到Android API级别24的良好支持.
For short, do not use forEach
like map.forEach { t, u -> Log.i("tag", t + u) }
(this is using Java 8 API, which does not work for Android API level <= 23).
Use it like map.forEach { (t, u) -> Log.i("tag", t + u) }
(this is using Kotlin API).
(Not two parameters. Just one parameter that is a pair.)