I am currently trying to figure out how to use Eclipse to program Escape models in java. I am quite new to Escape and Eclipse, and it has been a while since I programmed in java, so please excuse if this is a stupid question.
Basically, I have been haunted by strange Eclipse error messages. I tracked the last one down to this problem:
This works:
public class CoordinationGame extends Scape {
.
.
.
Scape lattice;
boolean test;
int test2;
{
test = true;
test2 = 3;
}
{
lattice = new Scape(new Array2DVonNeumann());
}
}
This gives strange error messages:
public class CoordinationGame extends Scape {
.
.
.
Scape lattice;
boolean test;
int test2;
test = true;
test2 = 3;
lattice = new Scape(new Array2DVonNeumann());
}
i.e. { expected afer int test2 and Syntax error on token "lattice", VariableDeclaratorId expected after this token.
As I said, Java has been some time, but IIRC, those brackets should not be required. This question establishes that this bracket usage is an initializing block, but this is probably not what I want to do here.
Does anyone know why Eclipse requires me to set these brackets, or what I could do to change this behaviour?
Thanks in advance!
Martin
PS: Some information that will probably be useful:
I use eclipse-indigo, installed the modelling toolkit AMP. I am not entirely sure how to check this, but I believe I am using jre6, as this is what it says in the JRE System Library tab of my package explorer. In the future, I plan to find a way to run the Escape modelling environment with Groovy, but that will be another question …
This has nothing to do with your IDE. Java does not allow statements at class level, it does however allow initializers at class level.
This is an instance initializer, it will be copied into all constructors by the compiler.
(See Java Tutorial > Initializing Fields)
In Java, you can write statements in
but nowhere else.