我正在尝试用 java.text.MessageFormat 做一个简单的逻辑:
MessageFormat cf = new MessageFormat(
"{0,choice, 1<hello|5<{1,choice,1<more than one|4<more than four}}");
Object[] array = {3, 1};
System.out.println(cf.format(array));
带字:如果第一个参数大于1,打印“hello”,如果大于5,第二个参数大于1,打印“more than one”,如果第二个参数大于4,打印“more than 4” ”。
我发现没有人说这是不可能的,但我得到了一个 IllegalArgumentException:
Choice Pattern incorrect: 1<hello|5<{1,choice,1<more than one|4<more than four}
有没有办法我可以做到这一点?谢谢!
整个堆栈跟踪:
Exception in thread "main" java.lang.IllegalArgumentException: Choice Pattern incorrect: 1<hello|5<{1,choice,1<more than one|4<more than four}
at java.text.MessageFormat.makeFormat(Unknown Source)
at java.text.MessageFormat.applyPattern(Unknown Source)
at java.text.MessageFormat.<init>(Unknown Source)
at test.Test5.main(Test5.java:18)
Caused by: java.lang.IllegalArgumentException
at java.text.ChoiceFormat.applyPattern(Unknown Source)
at java.text.ChoiceFormat.<init>(Unknown Source)
... 4 more