Brainteaser Drools: Testing Objects

This can be a hard one, since it requires from you to be familiar with Drools.

Consider the condition side of the following rules:

[java]
rule "object comparison one"
no-loop

when
$customer1 : Customer( )
$customer2 : Customer(this != $customer1)
then
System.out.println("Rule one – Objects are equal");
end
[/java]

[java]
rule "object comparison two"
no-loop

when
$customer1 : Customer( )
$customer2 : Customer(eval(this != $customer1))
then
System.out.println("Rule two – Objects are equal");
end
[/java]

Question(s):
Which of the two rules does valid comparison of the two Customer instances?
Which of the two rules is invalid? Why?

Looking forward for your answers dear readers

Resources:
Drools JBoss Rules 5.0 Developer’s Guide July 2009

 

One thought on “Brainteaser Drools: Testing Objects