What is the value of (list("a") == list("a"))

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

    Answer: B

    Today's Zen question: What is the meaning of == ?

    The meaning of the == for reference types (any Capital-letter type in Java such as String) is: exact equivalance of pointer values, i.e. same location in memory.

    Any call to cons(), list(), or new allocates brand-new storage, different from any existing storage that might be pointed to. Since there are two calls to list(), each one gets its own brand-new storage, and they are guaranteed to be in different locations.

    Contents    Page-10    Prev    Next    Page+10    Index