Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove Warning of Variable Shadowing in Kotlin

I couldn't find this info anywhere else.

Variable shadowing is a great feature in my opinion, yet in Kotlin we get warned for it every single time, thus requiring us to use @Suppress("NAME_SHADOWING") in every instance of it, if we wouldn't like it to warn us.

Is there a way to disable variable shadowing verifications, or suppress the warning globally?

like image 897
Roger Oba Avatar asked Nov 01 '18 14:11

Roger Oba


1 Answers

From Annotations in Kotlin

Put an annotation with the target file at the top level of a file, before the package directive or before all imports if the file is in the default package:

So right now the only solution is you can disable Suppress for file level. I don't find any way to disable for projects.

@file:Suppress("NAME_SHADOWING")
package com.your.package.name

import android.content.Context
import android.content.Intent
import android.os.Bundle

class SplashActivity : AppCompatActivity() {
    // Your class code here
}
like image 118
Son Truong Avatar answered Sep 29 '22 03:09

Son Truong