O
Oliver Wong
I'm aware of and follow the dogma that one should not call non-final
methods in a constructor. However, I'm wondering whether this applies to
static methods as well. My understanding of the reasoning behind this rule
is that subclasses may see fields in some unstable state, which tells me
that the rule need not apply to static methods. However, this code analysis
tool is reporting a warning with the following code:
<code>
public class Test {
public Test() {
staticMethod();
}
public static void staticMethod() {
//Does nothing.
}
}
</code>
Should I be declaring the staticMethod as being final? Will that even
have any effect on the semantics of the code? Or should I rather submit this
as a potential bug fix to the tools author?
- Oliver
methods in a constructor. However, I'm wondering whether this applies to
static methods as well. My understanding of the reasoning behind this rule
is that subclasses may see fields in some unstable state, which tells me
that the rule need not apply to static methods. However, this code analysis
tool is reporting a warning with the following code:
<code>
public class Test {
public Test() {
staticMethod();
}
public static void staticMethod() {
//Does nothing.
}
}
</code>
Should I be declaring the staticMethod as being final? Will that even
have any effect on the semantics of the code? Or should I rather submit this
as a potential bug fix to the tools author?
- Oliver