gpt4 book ai didi

java - 如何取消特定的Kotlinc/Javac编译器警告?

转载 作者:行者123 更新时间:2023-12-02 13:43:54 25 4
gpt4 key购买 nike

如何抑制类似于deprecationsKotlinCompile中的GradleJavaCompile

JavaCompile(有效):

tasks.withType(JavaCompile) {
configure(options) {
compilerArgs << '-Xlint:-deprecation'
}
}

KotlinCompile(无效):
tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile) {
kotlinOptions {
freeCompilerArgs = ["-Xjavac-arguments=-Xlint:-deprecation"]
}
}

引用:
  • https://kotlinlang.org/docs/reference/using-gradle.html#compiler-options

  • 类似问题:
  • kotlin supress warning deprecated for android
  • Mark unused parameters in Kotlin
  • Kotlin: Suppress unused Property?
  • How do I make the Kotlin compiler treat warnings as errors?
  • 最佳答案

    目前,Kotlin不支持“抑制编译器”警告。他们确实有一些类别可以压制。但是不同的是,唯一的办法是:

    @Suppress("DEPRECATION")
    有时,Surpress无法仅通过输入应在运行时运行的注释而无法工作。您可能需要添加如下内容
    val foo = error.asDynamic().response
    if (foo is AxiosResponse<String>) {
    @Suppress("UNCHECKED_CAST")
    val response = foo as AxiosResponse<String>
    }
    这不是你的情况。但是显然其他人也有类似的问题。我建议简要介绍一下reddit。以上情况并非如此,但可以带您进入。
    https://www.reddit.com/r/Kotlin/comments/bsgk5w/what_do_i_have_to_do_to_suppress_my_unchecked/

    关于java - 如何取消特定的Kotlinc/Javac编译器警告?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60853852/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com