Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

suppress an unused variable warning

Tags:

kotlin

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

like image 636
ycomp Avatar asked Feb 18 '17 09:02

ycomp


People also ask

How do I get rid of the unused variable warning?

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.

What does unused variable mean in C?

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.

How do I disable GCC?

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.


1 Answers

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.

like image 63
F. George Avatar answered Nov 15 '22 09:11

F. George