I have a question about logical assertions and truth maintenance. First of all, the Drools
manual states:
2.5.8.2. Important note: Equality for Java objects
It is important to note that for Truth Maintenance (and logical assertions) to work at
all, your Fact objects (which may be Javabeans) override equals and hashCode methods (from
java.lang.Object) correctly. As the truth maintenance system needs to know when 2
different physical objects are equal in value, BOTH equals and hashCode must be overridden
correctly, as per the Java standard.
Two objects are equal if and only if their equals methods return true for each other and
if their hashCode methods return the same values. See the Java API for more details (but
do keep in mind you MUST override both equals and hashCode).
Does this mean that in order to use logical assertions that I have to override equals and
hashCode? What if I have a class that I would like to use as fact in a logical assertions,
but for this class equality should be the same as identity. In other words, I don't
want to override equals and hashCode, because the versions of these methods inherited from
Object have the correct behavior for my application. Will this class still be okay to use
as facts in logical assertions?
Thanks,
-Hans