Source code:
private static ApplicationContext applicationContext; public static void setApplicationContextValue(ApplicationContext applicationContext){ SpringContextUtil.applicationContext = applicationContext; } public static ApplicationContext getApplicationContext(){ return applicationContext; }
The checkstyle on Jenkins prompts the setApplicationContextValue() method to “hides a field”
The error message usually appears on the setter method of the variable, the reason is:
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.
This means that two variables are set with the same name, one is a class variable, the other is a local variable in the method, the solution:
public static void setApplicationContextValue(ApplicationContext applicationContext1){
SpringContextUtil.applicationContext = applicationContext1;
}
Change the name of the internal parameter of the method to distinguish it from class variables, such as applicationContext1
.
Similar Posts:
- Java error: No enclosing instance of type E is accessible. Must qualify the allocation with an enclosing
- [Problems with the use of internal classes] No enclosing instance of type Outer is accessible. Must qualify the allocation with an enclo
- [Two Solutions] non-static method xxx() cannot be referenced from a static context
- Xlua#: How to Call C
- [Solved] Cannot make a static reference to the non-static field logMongoTemplate
- 【Java】No enclosing instance of type XXX is accessible. Must qualify the allocation with an enclos…
- Access permission problem caused by object. Clone() method
- On the non thread safety problem of simpledateformat and its solution
- Eclipse Error:The selection cannot be launched, and there are no recent launches
- [Solved] Java Call Error: java.lang.IllegalArgumentException: wrong number of arguments