Good day.

Do not tell me whether it is possible to create an enum so that each enumeration of the set corresponds to a constant (which can be called).

Something of the type (only with the ability to refer to a constant):

enum Entity{ TEXT{ public static final String REG_EXP_TEXT ="[a-wA-Wа-яА-я]"; }, NUMBER{ public static final String REG_EXP_TEXT ="(?:\\d*\\.)?\\d+"; } } 

I will be glad to any tips.

  • @ nolik03, If you are given an exhaustive answer, mark it as correct (click on the check mark next to the selected answer). - Nicolas Chabanovsky

2 answers 2

 enum Entity { TEXT("[a-wA-Wа-яА-я]"), NUMBER("(?:\\d*\\.)?\\d+"); public final String REG_EXP_TEXT; Entity(String regExp){ this.REG_EXP_TEXT = regExp; } } 

    I think in this case you better use the interface.

     public interface RegularExpressions { public static final String REG_EXP_TEXT ="[a-wA-Wа-яА-я]"; public static final String REG_EXP_TEXT ="(?:\\d*\\.)?\\d+"; } 

    The meaning will not change, and the readability of the code will be better. No, no, I'm not saying that this is unreal, just squats in use will push you to replace Enum with the Interface.

    like here

    • one
      Excuse me, what standard of C are you talking about? Is it true that C appeared public , String , final , interface ? - VladD
    • one
      @VladD hats off. Guilty) - Sergey Shustikov
    • @VladD and where is C? - smackmychi