Special characters in an enum

前端 未结 3 1333
情话喂你
情话喂你 2020-12-28 08:35

I want to put the special characters, the parentheses ( \'(\' and \')\' ) and the apostrophe (\'), in an enum.

I had this:

private enum specialChars{         


        
3条回答
  •  隐瞒了意图╮
    2020-12-28 08:58

    You should use something like this instead:

    private enum SpecialChars {
       LEFT_BRACKET('('),
       RIGHT_BRACKET(')'),
       QUOTE('\'');
    
       char c;
    
       SpecialChars(char c) {
         this.c = c;
       }
    
       public char getChar() {
         return c;
       }
    }
    

提交回复
热议问题