Reading material
Section 8.1 (pages 334-338),
Section 9.1 (pages 380-385)
Additional material
Implementation of a dictionary by means of a binary search tree in
PostScript and
PDF.
Dictionary
Question
Consider the following Java snippet.
Dictionary d = new ...();
d.insertItem(new Integer(2), new Object());
if (d.findElement(new Integer(3)) == Dictionary.NO_SUCH_KEY))
{
System.out.println("Not found!");
}
else
{
System.out.println("Found!");
}
Explain why we cannot use
Dictionary.NO_SUCH_KEY.equals(d.findElement(new Integer(3)))
instead of
d.findElement(new Integer(3)) == Dictionary.NO_SUCH_KEY).