Disable warning in IntelliJ for one line

后端 未结 7 1142
庸人自扰
庸人自扰 2020-12-15 02:03

I have a Java code line where IntelliJ displays a warning. How do I silence the warning in that particular line, without affecting warnings displayed in other lines?

7条回答
  •  孤街浪徒
    2020-12-15 02:48

    When compiling code using Kotlin language and IntelliJ here is a hint

    Here is a link to the github source where the compiler warnings have their origin and where the default error messages output by the Kotlin compiler are defined

    kotlin/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/rendering/DefaultErrorMessages.java

    If the compiler outputs "Variable ''{0}'' is never used" it origins from this line form DefaultErrorMessages.java

    MAP.put(UNUSED_VARIABLE, "Variable ''{0}'' is never used", NAME);
    

    To suppress the warning you can put a @Suppress() annotation before an unused variable in your code like this:

    @Suppress("UNUSED_VARIABLE")
    var y: Int = 3
    

    So the trick if the IntelliJ does not help you pop up suggestions pressing Alt+ENTER at a highlighted expression is to look inside DefaultErrorMessages.java if you can find the error message and the keyword to supress a particular warning using @Suppress(..names)

    This topic is not marked "Kotlin" but at least marked IntelliJ

提交回复
热议问题