How can I suppress the inspection in Kotlin for an unused variable
val xyz = abc
I get the squiggly line but ALT-ENTER
is useless for this, I tried also to create in another method several variables unused and they also lack the ALT-ENTER
ability to ignore the warning. Although I have definitely used ALT-ENTER
for this in the past, although maybe it was only in java, can't remember.
So I must manually construct it by hand. I've been trying several variations but I can't get anything to work. Please tell me the correct //noinspection
or @SupressWarnings
to use, thanks
Solution: If variable <variable_name> or function <function_name> is not used, it can be removed. If it is only used sometimes, you can use __attribute__((unused)) . This attribute suppresses these warnings.
No nothing is wrong the compiler just warns you that you declared a variable and you are not using it. It is just a warning not an error. While nothing is wrong, You must avoid declaring variables that you do not need because they just occupy memory and add to the overhead when they are not needed in the first place.
To answer your question about disabling specific warnings in GCC, you can enable specific warnings in GCC with -Wxxxx and disable them with -Wno-xxxx. From the GCC Warning Options: You can request many specific warnings with options beginning -W , for example -Wimplicit to request warnings on implicit declarations.
In IntelliJ IDEA, a right-side arrow on an ALT+ENTER context menu (like this: ) means that you can use your arrow keys to navigate further along the menu. In this case, it leads to your answer:
@Suppress("UNUSED_VARIABLE")
val unused = ""
If you do not get the initial context menu (Remove variable '...'
), you may have disabled the "Unused assignment" inspection in your current project. You can fix this by going to Settings -> Editor -> Inspections.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With