Java compilation error: open enumeration
I encountered a very strange mistake and I couldn't figure out how to solve it
Projects compiled well on Windows cannot be compiled on Linux, but the following errors occur:
Cannot switch on a value of type AClass.Bbb. Only convertible int values,strings or enum variables are permitted
, even if the type is an enumeration
The code of the class is as follows:
public class AClass { private enum Bbb { ONE,TWO; } public void aMethod(List<Bbb> arg) { for (Bbb en : arg) { switch (en) { .... } } } }
EN in the switch (EN) is underlined with the above error notification
Does anyone else have it? Is there a way to solve this problem?
UPD java version:
java version "1.7.0_25" Java(TM) SE Runtime Environment (build 1.7.0_25-b15) Java HotSpot(TM) 64-Bit Server VM (build 23.25-b01,mixed mode)
Solution
If you use jdk1 7. The problem should disappear Please follow the steps below to view the
>Open Project Properties > click "java compiler" > check mark "enable project specific settings" > set all drop-down menus to 1.7 > click OK > clean project to trigger reconstruction
If you are below, the problem will arise again
>Open Project Properties > Click java compiler > clear enable project specific settings > click OK > clean up the project to trigger the rebuild (it will rebuild automatically)
If I do the following, this is what I see
>Open Project Properties > Click java compiler > click Configure workspace Settings > I see compiler compliance level = 1.7 > I see use default compliance settings selected
Hope this can help!!