Operand Coercing Rules
Before the operator is applied, the EL evaluator coerces the types of the operand values. An exception is thrown if no rule matches, the coercing fails, or applying the operator leads to an exception.
Property and array accessor operators
An expression of the form
${exprA.identifierB} is evaluated the same way as
${exprA['identifierB']}.
To evaluate an expression of the form
${exprA[exprB]}, the following rules are used:
If
exprAisnull, returnnull.If
exprBisnull, returnnull.If
exprAis aMapwith a key matchingexprB, return the value.If
exprAis aListor array with an index matchingexprBcoerced to anint, return the value.If
exprAis a bean with a property matchingexprBcoerced to aString, return the value.
Arithmetic operators
For addition, subtraction, and
multiplication, if any operand is null, the result
is 0. Otherwise both operands are coerced to numbers (to
BigDecimal if one of them is
BigDecimal or if one is
BigInteger and the other is
Float, Double, or a
String with floating-point syntax, to
double if one of them is Float,
Double, or a String with
floating-point syntax, to BigInteger if one of
them is BigInteger, to long
otherwise), and the result of applying the operator is returned.
For division, if any operand is null, the result
is 0. Otherwise both operands are coerced to numbers (to
BigDecimal if one of them is
BigInteger or BigDecimal, to
double otherwise), and the result of applying the
operator is returned.
For modulo, if any operand ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access