I was setting out to write a piece of code today in Eclipse, and I started out like so:
public class MyClass {
System.currentTimeMillis();
}
(Ignore the fact that I wasn't thinking straight, etc. etc...)
I get this compile error:
Syntax error on token "currentTimeMillis", Identifier expected after this token
It works if I change that statement to an assignment statement:
long time = System.currentTimeMillis();
Of course, it doesn't cause errors if placed inside a method body and also within blocks inside the class body.
Why is this? Is there some compiler level rule that says that only assignment statements or declarations should be present inside the class body?
TIA
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…