Static Initializer in Joe-E
Mohsen Vakilian <mvakili2-nzINlOoChub2fBVCVOL8/[email protected]>
| Newsgroups | gmane.comp.lang.e.general |
|---|---|
| Message-ID | <[email protected]> |
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;
}
}
_______________________________________________
e-lang mailing list
[email protected]
http://www.eros-os.org/mailman/listinfo/e-lang