Here’s what I’ve written:
public class JavaApplication4 {
private RunMode runMode;
private enum RunMode {
STOP, START, SCE, SIE;
void reset() {
this = STOP; // <=== 'cannot assign a value to final variable this.'
}
}
}
As noted, the assignment to ‘this’ is flagged. Why is ‘this’ final, and how can I change the value of an enum variable with an enum instance method?
It really doesnt make sense to reassign an already instantiated Enum.
Think of Enums as singleton objects. In your case, START, STOP, SCE and SIE are all singleton objects that are pre-instantiated. All you do is pass around their reference in your application.