ILOG JRules User Guide > Optimizing Execution > Concepts > Autoboxing Options

The ILOG Rule Language (IRL) supports autoboxing and autounboxing as in Java 5. This feature provides automatic conversion of data of primitive type (for example int) to the corresponding wrapper type (java.lang.Integer), and vice versa.

The Java primitive types are boolean, char, byte, short, int, long, float, and double. Autoboxing and unboxing works for all these types. For example, if you want to add an integer in a collection, you can write:

collection.add(12);

Autoboxing or autounboxing can occur in assigments, method or function arguments and return values, binary operators, unary operators (except ++ and --), casts, and insertion/retraction of objects in working memory.

Enabling and Disabling Autoboxing

Autoboxing is enabled by default in JRules. To disable autoboxing, you must set the property ilog.rules.engine.autoboxing to false. The property can be set in the engine configuration file (see The Configuration Resource File).

Disabling autoboxing has also an impact on the semantic of inserting wrapper types instances in the working memory as described in Working Memory and Autoboxing.

Cache of Values

In Java 5, some wrapper instances are cached for better performance. For example, the java.lang.Integer are cached for values between -128 and 127. It means that if you write:

Object o1 = 10;
Object o2 = 10;

o1 == o2 returns true.

But if you write:

Object o1 = 1000;
Object o2 = 1000;

o1 == o2 returns false.

Caching is done in IRL, based on Java 5 caching if you use Java 5, or done by JRules if you use an older JVM.

Working Memory and Autoboxing

As introducing autoboxing and the value cache changes the way objects can be inserted into the working memory (for example you can now write insert 4;), the semantic of inserting wrapper types instances into working memory changed. Now the equality of such instances is based on the equals method.

So, if now you write:

insert 1000;
insert 1000;

You will have only one instance of java.lang.Integer in the working memory.

If you disable autoboxing, or work with an older version of JRules, you would get two instances of java.lang.Integer in the working memory.

Related Concepts

Ruleset Variables

Related Tasks

Defining Ruleset Variables
Working with Technical Rules

Related Reference

Rule Engine Configuration Properties
ILOG Rule Language

Related Samples and Tutorials

Rule-Based Programming