NewApi皮棉的不同行为

时间:2020-03-29 02:38:57

标签: android kotlin lint

最小api级别为21的代码:

interface SampleInterface {

    fun interfaceFun() {
        val value = HashMap<String, String>().getOrDefault("a", "b")
    }

    companion object {
        @JvmStatic
        fun companionFun() {

        }
    }
}

IDE看到两个问题: enter image description here enter image description here

  1. getOrDefault需要api级别24
  2. @JvmStatic用于伴随方法也需要api级别24

./gradlew lintDebug仅中止问题1的构建,而不中止问题2。有什么区别?

1 个答案:

答案 0 :(得分:1)

根据Supported Java 8 language features and APIs chart,Android的所有API级别均支持默认和静态接口方法。