A Summary of Java and RL Differences

This appendix describes the differences between the RL Language and Java languages.

A.1 RL Differences from Java

  • RL does not include interfaces or methods.

  • RL global variables are similar to Java static class variables, but there is one instance for each rule session.

  • RL does not have a static keyword.

  • RL has rulesets instead of packages. Rulesets group definitions and actions.

  • Instances of RL and Java classes can be asserted as facts in working memory.

  • RL facts are not garbage collected; they must be explicitly retracted.

  • RL is interpreted. There is no compilation or class loading. Classes and functions must be defined before they are used.

  • RL classes may not contain constructors or methods, only data fields. The data fields behave like Java bean properties.

  • Java bean properties can be accessed as fields in RL.

  • The new operator can explicitly assign values to named properties, regardless of whether a constructor is defined. The fact operator can match values to named properties and retrieve, using the var keyword, values from named properties. A property is either a Java bean property, for Java objects, or a field, for RL objects.

  • RL arrays are limited to one dimension.

  • The if and while actions must be in a block, enclosed in curly braces ({}).

  • RL does not include a switch action, continue statement, break statement, or labeled statements for breaking out of nested loops.

  • An RL for loop cannot contain multiple comma separated initialization or update expressions.

  • RL does not support bitwise & and | operators.

  • RL supports function overloading and Java method overloading using best fit.

  • RL variables must be initialized when they are defined.

  • For RL and Java objects, == always invokes the object equals method. RL does not allow testing for object reference equality. For objects,!= does not test for inequality of object references, but rather is the negation of the equals methods.

    Thus, the statement:

    if (object1 != object2){}

    Is equivalent to the statement:

    if (! (object1.equals(object2)){}
  • Forward references to classes or functions is not allowed.

  • In Java the Java Bean introspector will include write only properties. RL does not include such properties as Beans, since they cannot be reasoned on in a rule. Thus, in order for Java fact type bean properties to be properly accessed in RL they must have both a getter and setter. Properties which have a setter but not a getter, that is write-only properties, are not allowed in the RL new syntax.

    For example, if a bean Foo only has the method setProp1(int i), then you cannot use the following in RL, Foo f = new Foo(prop1: 0)