Am 08.10.2009 12:59, David Holmes - Sun Microsystems schrieb:
Hi Ulf,

It's a memory model issue. The code is like this:

     public String getName() {
         if (name == null)
            name = getName0();
         return name;
     }

but in theory, accoridng to the JMM experts, it could act as if it does this:

  public String getName() {
    String tmp1 = name; // sees null
    String tmp2 = name; // sees non-null
    if (tmp2 == null)
      tmp1 = name = getName0();
    return tmp1;
  }

imagine the temporaries are registers.

Oops, java programming is not simple as it looks like. Can you give me a link, where I can read more about that subject / JMM?
David, thanks for your explicit explanation.

-Ulf


Reply via email to