java - illegal reference to static field from initializer -


i new enums in java , confused why code compiles fine

enum scale5 { good(), better(), best(); static  scale5 s=good; } 

but code fails:

enum scale5 { good(), better(), best(); scale5 s=good; } 

and error : illegal reference static field initializer. dont understand reason.i relatively inexperienced in enums please dump down me.thanks lot!

the question asked here cannot refer static enum field within initializer? exact opposite of have asked.in case declaring s static compiles code fine.

think of enum this:

public final class scale5 {      public static final scale5 = new scale5();      public static final scale5 better = new scale5();      public static final scale5 best = new scale5();       static scale5 s = good;//works because initialized first;      scale5 ss = good;//doesn't work because in order initialize good,                        //ss must assigned object not yet initialized; } 

Comments

Popular posts from this blog

c++ - Delete matches in OpenCV (Keypoints and descriptors) -

java - Could not locate OpenAL library -

sorting - opencl Bitonic sort with 64 bits keys -