执行此代码时返回ArrayoutOfBoundsException:0 源代码:
public static String foo(final EnumClass enumObject){
switch(enumObject){
case CASE1 : return "case1";
case CASE2 : return "case2";
default : return "invalid";
}
}
Enum Def:
EnumClass{
CASE1,CASE2;
}
测试代码:
public void testFoo(){
assertEquals("case1",foo(EnumClass.CASE1));
}
答案 0 :(得分:0)
以下传递没有错误,因此代码中的其他内容导致错误:
public class TestClass {
public static String foo(final EnumClass enumObject) {
switch (enumObject) {
case CASE1:
return "case1";
case CASE2:
return "case2";
default:
return "invalid";
}
}
enum EnumClass {
CASE1, CASE2;
}
@Test
public void testFoo() {
Assert.assertEquals("case1", foo(EnumClass.CASE1));
}
}