JavaMemoryModel: Corner cases for final fields

From: Jan-Willem Maessen (jmaessen@MIT.EDU)
Date: Tue Sep 12 2000 - 11:51:43 EDT


Bill, I'm not sure I totally understand where you want to go with you
example. Shouldn't we be encouraging programmers to write this sort
of thing instead?

class A {
   final int x;
   private static A lastA;
   A (int i) {
// **moved** lastA = this;
        x = i;
        }
   static synchronized A makeA(int i) {
        lastA = new A(i); // ** Bind lastA in the synchronized method
        return lastA;
        }
   static synchronized A getLastA() {
        return lastA;
        }
   }

-Jan-Willem Maessen
-------------------------------
JavaMemoryModel mailing list - http://www.cs.umd.edu/~pugh/java/memoryModel



This archive was generated by hypermail 2b29 : Thu Oct 13 2005 - 07:00:27 EDT