Java – refactoring constant classes to enumerations in Android studio

I want to refactor the old code that uses a kind of constant to enumerate. The code has been used in several places in the code. (I know it is possible in eclipse, but I can't find it in IntelliJ refactoring dialogs). Current status:

public class MyConstants {
    public static String MY_CONSTANT_1 = "MY_CONSTANT_1_VALUE";
    public static String MY_CONSTANT_2 = "MY_CONSTANT_2_VALUE";
    public static String MY_CONSTANT_3 = "MY_CONSTANT_3_VALUE";
}
public class MyClass {
    //usage of constant
    if (mString.equals(MyConstants.MY_CONSTANT_1)){}
}

Expected results:

enum MyEnum {
        MY_CONSTANT_1("MY_CONSTANT_1_VALUE"),MY_CONSTANT_2("MY_CONSTANT_2_VALUE"),MY_CONSTANT_3("MY_CONSTANT_3_VALUE")
        private final String value;
        MyEnum(String aValue){
            value = aValue;
        }
        public String getValue(){
           return value;
        }
}
public class MyClass {
    //usage of constant
    if (mString.equals(MyConstants.MY_CONSTANT_1.getValue())){}
}

Note: I know that enumeration is not recommended for Android official documentation, but it's not my problem

resolvent:

You cannot automatically use Android studio

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>