Java compilation error: switch on enum

后端 未结 3 1238
梦谈多话
梦谈多话 2021-01-20 17:54

I came across a very weird error that I just can\'t figure out how to solve.

A project, that compiles just fine on Windows, doesn\'t compile on Linux with the follow

3条回答
  •  离开以前
    2021-01-20 18:54

    I have tried your code

    public class AClass {
         enum Bbb {
            ONE,
            TWO;
        }
        public void aMethod(List arg) {
            for (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 list = new ArrayList();
            list.add(Bbb.ONE);
            list.add(Bbb.TWO);
    
            new AClass().aMethod(list);
        }
    }
    

    It is working fine.
    I dont know the pros and cons of passing argument like this List arg but atleast it is not error as much as i know in java 7

提交回复
热议问题