From: <jbo...@li...> - 2006-05-02 09:31:36
|
Author: mic...@jb... Date: 2006-05-02 05:31:30 -0400 (Tue, 02 May 2006) New Revision: 4037 Modified: labs/jbossrules/trunk/documentation/manual/en/Chapter-Rule_Language/Section-Rule.xml Log: autoboxing Modified: labs/jbossrules/trunk/documentation/manual/en/Chapter-Rule_Language/Section-Rule.xml =================================================================== --- labs/jbossrules/trunk/documentation/manual/en/Chapter-Rule_Language/Section-Rule.xml 2006-05-02 09:14:42 UTC (rev 4036) +++ labs/jbossrules/trunk/documentation/manual/en/Chapter-Rule_Language/Section-Rule.xml 2006-05-02 09:31:30 UTC (rev 4037) @@ -870,5 +870,17 @@ <para>Grouping is similar to using parentheses in algebra, it makes the order of operations explicit.</para> </section> + </section> + + <section> + <title>A note on autoboxing and primitive types</title> + <para> + Java 5 supports autoboxing and unboxing between primitives of appropraite types. This makes for very convenience and easier to read code. However, as drools runs in J2SE 1.4 as well, we can't rely on this. Thus we have to autobox at times. Fields that are referred to are autoboxed in the corresponding object type automatically (if they are already an object, then there is no change). However, it is important to note that they are not "unboxed" automatically. Thus if you bind to a field that is an "int" in your object model, it will behave like an Object in the rule (ie predicates, return value constraints and the RHS). + </para> + <para> + As a general rule, if possible, make your fields object types (at least until java 5), or at least think of your fields as object types even if they are not to start with). Another special note, is that for return value constraints, the return value snippet of code must return an Object (not a primitive). + Now, I bet you can't wait for Java 5 to be the minimum ! + </para> + </section> </section> \ No newline at end of file |