USAI - Use of Static Attribute for Initialization
Non-final static attributes should not be used in initializations of attributes.
Wrong
static int state = 15;
static int attr1 = state;
static int attr2 = ClassA.state;
static int attr3 = ClassB.state;
}
class ClassB {
static int state = 25;
}
Tip: Either make static attributes used for initialization final, or use another constants for initialization.
Right
static int state = 15;
static final int INITIAL_STATE = 15;
static int attr1 = INITIAL_STATE;
static int attr2 = ClassA.state;
static int attr3 = ClassB.state;
}
class ClassB {
static final int state = 25;
}