22.4. Banking Example: Rule in Example2.drl

rule "Rule 02"
    when
        Number( $intValue : intValue )
    then
        System.out.println( "Number found with value: " + $intValue ); 
end
Output:
Loading file: Example2.drl
Inserting fact: 3
Inserting fact: 1
Inserting fact: 4
Inserting fact: 1
Inserting fact: 5
Number found with value: 5
Number found with value: 1
Number found with value: 4
Number found with value: 1
Number found with value: 3
  • This is a basic rule for printing out the specified numbers. It identifies any facts that are Number objects and prints out the values. Notice the use of the abstract class Number.
  • The pattern matching engine is able to match interfaces and superclasses of asserted objects.
  • The output shows the DRL being loaded, the facts inserted and then the matched and fired rules. You can see that each inserted number is matched and fired and thus printed.