源代码:

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



相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-12-31
  • 2021-11-20
  • 2022-12-23
  • 2021-07-25
  • 2021-09-22
  • 2021-09-01
猜你喜欢
  • 2021-06-18
  • 2022-12-23
  • 2021-06-05
  • 2022-12-23
  • 2021-08-26
  • 2021-07-15
  • 2021-05-24
相关资源
相似解决方案