Java Enum access to private instance variable

后端 未结 6 1828
名媛妹妹
名媛妹妹 2021-02-05 10:50

Consider the example:

enum SomeEnum {
    VALUE1(\"value1\"),
    VALUE2(\"value2\"),
    VALUE3(\"value3\")
    ;
    private String value;

    private SomeEnu         


        
6条回答
  •  野趣味
    野趣味 (楼主)
    2021-02-05 11:22

    SomeEnum.VALUE1 = "Value4" ... actually does not work.

    More important, VALUE1 will always only be equal to VALUE1 and not VALUE2 or VALUE3, independent of it's member value.

提交回复
热议问题