Issue
I have a Parent class(from GMF to be specific) with static initializer method initDefaults
public Class Parent{
public static initDefaults(){
...
}
}
I have a custom child class that extends the Parent class
public Class CustomSubclass extends Parent{
public CustomSubclass(){
super();
..
}
}
In my calling class I am calling initDefaults
method with the CustomSubclass name i.e.,
CustomSubclass.initDefaults()
but eclipse automatically corrects this and types Parent.initDefaults()
.
public Class ExampleClass{
public void initializer(){
// CustomSubclass.initDefaults(); this is what I typed
Parent.initDefaults(); // this is what eclipse corrected
...
}
}
Both ExampleClass
and CustomSubclass
reside under same package while Parent
is from GMF as dependency.
Why is this happening? I have other plugin project with the same setup and there this is not the case and the CustomSubclass
name is retained as it is. But I did not implement the other plugin project.
Whenever I am typing the subclass name with superclass method, the superclass is automatically imported and eclipse corrects the subclass name with the superclass name.
Solution
Eclipse provides for this code smell (the compilation would not fail, but it's harder to read, a bit slower and there is no real benefit since static methods cannot be overridden):
- the warning/error Indirect access to static member which is disabled by default and
- the clean-up or/and save action Member Accesses > Static Access which is enabled by default.
These defaults can be overridden by the following project specific settings (tick the Enable project specific setting checkbox):
- Warning/error: Project > Properties: Java Compiler > Errors/Warnings
- Clean up: Project > Properties: Java Code Style > Clean Up
- Save action: Project > Properties: Java Editor > Save Actions
Answered By - howlger
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.