Mark unused parameters in Kotlin

后端 未结 4 1714
青春惊慌失措
青春惊慌失措 2020-12-14 05:40

I am defining some functions to be used as callbacks and not all of them use all their parameters.

How can I mark unused parameters so that the compiler won\'t give

4条回答
  •  伪装坚强ぢ
    2020-12-14 05:42

    One can disable these warnings by adding a kotlin compile option flag in build.gradle. To configure a single task, use its name. Examples:

    compileKotlin {
        kotlinOptions.suppressWarnings = true
    }
    
    compileKotlin {
        kotlinOptions {
            suppressWarnings = true
        }
    }
    

    It is also possible to configure all Kotlin compilation tasks in the project:

    tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).all {
        kotlinOptions {
            // ...
        }
    }
    

    If one is using kotlin in Android and want to suppress kotlin compiler warnings, add below in app-module build.gradle file

    android{
        ....other configurations
        kotlinOptions {
            suppressWarnings = true
        }
    }
    

    Whether you really need to suppress all kotlin warning for your project or not, its up to you.

提交回复
热议问题