[e-lang] Static Initializer in Joe-E

Mohsen Vakilian mvakili2 at illinois.edu
Fri Sep 18 22:57:51 EDT 2009


I believe Joe-E should disallow calls to static methods in static
initializers for the same reason that it forbids calls to instance methods
in constructors.
The following is an example of what can go wrong if you let static
initializers invoke static methods. In this example, method m, which is
verified  to be pure by Joe-E, returns two different results given the same
input (m takes no inputs).

import org.joe_e.Immutable;

public class InitializerBlock implements Immutable {
    public final static int a;
    public final static int d;

    static {
        int a1 = m();
        a = 1;
        int a2 = m();
        d = a2 - a1;
    }

    static int m() {
        return a;
    }

    public static void main(String[] args) {
        assert InitializerBlock.d == 0;
    }
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.eros-os.org/pipermail/e-lang/attachments/20090918/29e9d447/attachment.html 


More information about the e-lang mailing list