How do I refactor Java constants to enums with eclipse?
I found no built-in functionality in eclipse: http://help.eclipse.org/juno/index.jsp?topic=%2Forg.eclipse.jdt
Refactoring never changes the "external behavior"!
For example:
public enum Test {
NAME1("abc");
Test(String name) {}
public static final String _NAME1="abc";
public static void main(String[] args) {
String k = Test._NAME1;
String m = Test.NAME1;
}
}
If you refactor _NAME1
to NAME1
(enum) ,the code crashes on instantiation of m
. The refactoring would never be successful!