OiO.lk Blog Android How do I correctly suppress an unused variable warning in Kotlin?
Android

How do I correctly suppress an unused variable warning in Kotlin?


I tried to suppress a warning using a couple of different methods, but I ended up with this one:

class RotationGestureDetector(
    @Suppress("UNUSED_PARAMETER") private val context: Context, // Accepting Context for consistency
    private val listener: OnRotationGestureListener
)

This gives the following warnings:

Warning:(35, 16) Redundant suppression
Warning:(35, 47) Property 'context' is never used

I also tried placing @Suppress("UNUSED_PARAMETER") before the class (not that I wanted to extend its scope to the whole file, just to try), and using an underscore in front of the variable name. I would like to know the correct way to suppress that warning in case I’m leaving the parameter reserved for future use, but I don’t want to be distracted by the warning.

This warning shows up when I making a commit.



You need to sign in to view this answers

Exit mobile version