Chapter 5. Coercing Objects to Types

Table of Contents

Interpreting Objects as Booleans
Interpreting Objects as Numbers
Interpreting Objects as Integers
Interpreting Objects as Collections

Here we describe how OGNL interprets objects as various types. See below for how OGNL coerces objects to booleans, numbers, integers, and collections.

Interpreting Objects as Booleans

Any object can be used where a boolean is required. OGNL interprets objects as booleans like this:

  • If the object is a Boolean, its value is extracted and returned

  • If the object is a Number, its double-precision floating-point value is compared with zero; non-zero is treated as true, zero as false.

  • If the object is a Character, its boolean value is true if and only if its char value is non-zero.

  • Otherwise, its boolean value is true if and only if it is non-null.