![]() |
Examples 8.1.2.2: |
The single feature of the required library class ELT_EQ is used in individual examples below. None of the examples given is a complete class nor necessarily a 'complete' method.
In all of the examples it will be assumed that the code shown is in a class called, say, EXAMPLE.
This feature provides a test for equality which is based either on value equality (if the object derives from $IS_EQ) or object equality - if not immutable! Consider the following four example cases -
which is valid because the type CARD derives from $IS_EQ and gives res the value false. Contrast this with -
which makes res also false - but this time because neither are objects - they have not yet been created! This kind of error is very easy to fall into, even for quite experienced O-O programmers! Look, however, at the next example -
What is the value of res under these circumstances? There are two created objects - although they do not themselves have an equality test. Contrast that with -
for which, at last, res is true - because they are the same object! (Oh! By the way! That must mean that res was false in the previous example!)
![]() |
Specification Index | ![]() |
Language Index | ![]() |
Section 8 Index |
Comments
or enquiries should be made to Keith Hopper. Page last modified: Thursday, 25 May 2000. |
![]() |