Kotlin扩展功能突然需要api级别24 [英] Kotlin Extension Functions suddenly require api level 24

查看:123
本文介绍了Kotlin扩展功能突然需要api级别24的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚注意到了这个皮棉错误:

I just noticed this lint error:

调用需要API级别24(当前最小值为19)java.util.map#foreach

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

当我在Kotlin的MutableMap上对每一个使用扩展功能时. 当我编写该行时并没有发生这种情况,但现在就在那里. 而且我在另一台机器上没有看到此错误.

when I use the extension function forEach on a MutableMap in Kotlin. This didn't happen when I wrote the line, but its there now. And I'm not seeing this error on my other machine.

推荐答案

您使用的不是kotlin.collections.MutableMap.forEach.

您使用的似乎是Java 8中的Map.forEach.

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

阅读本文: http://blog.danlew. net/2017/03/16/kotlin-puzzler-whoose-line-is-it-anyway/

这似乎是一个常见的错误.

This seems to be a common mistake.

Android API级别24很好地支持Java 8.

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

简而言之,请勿像map.forEach { t, u -> Log.i("tag", t + u) }那样使用.
map.forEach { (t, u) -> Log.i("tag", t + u) }一样使用.
(不是两个参数.只有一个参数是一对.)

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.)

这篇关于Kotlin扩展功能突然需要api级别24的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆