Hi to all,
in reading the ref manual in section...
6.5.10.1 The #this and #root variables
The variable #this is always defined and refers to the current evaluation object (against which unqualified references are resolved). The variable #root is always defined and refers to the root context object. Although #this may vary as components of an expression are evaluated, #root always refers to the root.
we see #primes.?[#this>10] is this a groovy dot operator ' myArray.?[condition]' ?Code:// create an array of integers List<Integer> primes = new ArrayList<Integer>(); primes.addAll(Arrays.asList(2,3,5,7,11,13,17)); // create parser and set variable 'primes' as the array of integers ExpressionParser parser = new SpelExpressionParser(); StandardEvaluationContext context = new StandardEvaluationContext(); context.setVariable("primes",primes); // all prime numbers > 10 from the list (using selection ?{...}) // evaluates to [11, 13, 17] List<Integer> primesGreaterThanTen = (List<Integer>) parser.parseExpression("#primes.?[#this>10]").getValue(context);
what would it translate to in java code..?
I can't seem to find an example/explanation for ' .? 'Code:List<Integer> primesGreaterThanTen; for (Integer : primes){ primesGreaterThanTen.add( (this > 10) ? this : null); }
Is there anything to explain this syntax ?
Thanks![]()


Reply With Quote