jenkins checkstyle:local variable hides a field


源代碼:

1
2
3
4
5
6
7
8
//應用上下文
private  static  ApplicationContext applicationContext;
public  static  void  setApplicationContextValue(ApplicationContext applicationContext){
     SpringContextUtil.applicationContext = applicationContext;
}
public  static  ApplicationContext getApplicationContext(){
     return  applicationContext;
}

Jenkins上的checkstyle提示setApplicationContextValue()方法“hides a field”

該錯誤提示一般出現在變量的setter方法上,原因是:

It means you've got two different variables with the same name - myBoard. One of them is a field in your class. Another one is a local variable, that is, one that you've declared inside a method.

It's a bad idea to have two variables with the same name. It can make your code very confusing and difficult to maintain.

意思就是兩個變量設置了相同的名稱,一個是類變量,一個是方法內局部變量,解決方法:

1
2
3
public  static  void  setApplicationContextValue(ApplicationContext applicationContext1){
     SpringContextUtil.applicationContext = applicationContext1;
}

將方法內形參名稱改一下,與類變量區分開,比如applicationContext1




免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM