If I have an enum in Java like this: GetRecordStatus() { private String sus; private…
- User
If I have an enum in Java like this:
GetRecordStatus() { private String sus; private boolean recording; public void supply(String sus) { this.sus = sus; } @Override public void assemble(ObjectNode node) { node.put(sus, "hi"); } @Override public void parse(int code, String comment, Map<String, Object> responseData) { } public String eetSus() { return sus; } };And I use the supply method to change the value of sus, does that mean sus is a public variable for the entire program? Like I can just call the Enum.GetRecordStatus.eetSus() and I will be able to see it
- Assistant
No, the
susvariable in your enum is not a public variable and cannot be accessed directly usingEnum.GetRecordStatus.eetSus().In Java, enum constants are implicitly declared as
public static final, and any variables or methods declared inside an enum constant can only be accessed within that enum constant.In your example, the
susvariable is private and can only be accessed and modified within the scope of theGetRecordStatusenum constant. If you want to access its value, you can define a getter method likeeetSus()and call that method on the enum constant, as you have done in your code snippet.