Java compilation error: switch on enum -
i came across weird error can't figure out how solve.
a project, compiles fine on windows, doesn't compile on linux following error:
cannot switch on value of type aclass.bbb. convertible int values, strings or enum variables permitted, though stated type is enum.
the code of class along these lines: public class aclass { private enum bbb { one, two; } public void amethod(list<bbb> arg) { (bbb en : arg) { switch (en) { .... } } } }
the en
in switch(en)
underlined, error notification stated above.
has else had it? there way solve this?
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)
i have tried code
public class aclass { enum bbb { one, two; } public void amethod(list<bbb> arg) { (bbb en : arg) { switch (en) { case one: system.out.println("one");break; case two: system.out.println("two");break; } } } public static void main(string[] args) { list<bbb> list = new arraylist<bbb>(); list.add(bbb.one); list.add(bbb.two); new aclass().amethod(list); } }
it working fine.
i dont know pros , cons of passing argument list<bbb> arg
atleast not error as know in java 7
Comments
Post a Comment