Suppose that we say:

Cons lst = list("a", "b", "c");
boolean test = ( lst == reverse(reverse(lst)) );

What is the value of test?

  • A: true
  • B: false
  • C: null
  • D: error
  • E: could be true or false

    Answer: B

    reverse makes a backward copy of its input. What == does, for any reference types, is to compare equality of pointer values, i.e., do the two pointers reference the same numeric address in memory? Since reverse(reverse(lst)) is a backward copy of a backward copy, it resides at a different address than the original.

    Contents    Page-10    Prev    Next    Page+10    Index