0
我正在使用JCodemodel动态生成Java类。下面是创建一个switch语句的代码,其默认情况是抛出一个Exception。JCodemodel中的异常消息
JSwitch valueswitch;
AbstractJClass exception = ref(IllegalArgumentException.class);
valueswitch._default()
.body()
._throw(JExpr._new(exception));
生成的类看起来像下面
public static Example switchCode(String code) {
switch (code) {
case "1":
{
return A;
}
default:
{
throw new IllegalArgumentException();
}
}
}
现在我想将消息添加抛出像
throw new IllegalArgumentException("Invalid code "+ code);
我怎样才能JCodemodel实现这一例外。任何帮助,将不胜感激。