I think I see your problem. I am sorry that the other answers do not relate to this.
So, Java has this idea, which is shared by some other languages, because something is a valid expression, does not mean that this thing in itself is a valid statement.
For example, this code will complain in a similar way:
Integer i = 4; i+3;
And yet I can use i+3 (go unboxing!) Elsewhere to denote " 7 ":
System.out.println(i+3); // this is fine
It is a bit confusing, because unlike some languages ββthat have this difference between an expression / expression, java allows you to use any method call - whether it returns a value or not - as an operator. However, most java statements themselves do not form a valid statement.
Similarly, this does not compile:
Integer i = 4; i;
See details at http://java.sun.com/docs/books/jls/second_edition/html/statements.doc.html#32588
source share