java What is {{ }} and -> in the following enum
本问题已经有最佳答案,请猛点这里访问。
我有一个非常基本的疑问!
{{}}和 - >是什么意思,它对于以下枚举意味着什么?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | public enum BuyUsedFeatureFilters implements FeatureFilter { BuyUsedContext {{ requestProperty = req -> isBuyUsedContext(req); }}; RequestProperty<Boolean> requestProperty; PropertyCondition defaultCondition = PropertyCondition.IGNORE; @Override public RequestProperty<Boolean> requestProperty() { return requestProperty; } private static boolean isBuyUsedContext(RequestContext requestContext){ String buyUsedParam = requestContext.getParameters().get("buyUsedParam"); if (StringUtils.equals(buyUsedParam,"buyUsed")) { return true; } return false; } } |
JLS#8.9.2允许该语法(强调我的):
In addition to enum constants, the body of an enum declaration may contain constructor and member declarations as well as instance and static initializers.
在您的情况下,它是一个实例初始值设定项,它为