Reputation: 1447
I saw a piece of java code like this:
int y = 100;
boolean x = y <= 0;
System.out.println(x);
<=
is strange for me due to this using way, Could anyone explain the <=
here, how can I use it?
Upvotes: 0
Views: 253
Reputation: 13834
Read it as:
boolean x = (y <= 0);
This means that:
Upvotes: 5
Reputation: 178263
The assignment operator =
is of lower precedence in Java than <=
, so <=
is performed first. The boolean
result of y <= 0
is assigned to x
. It could have more clearly written:
boolean x = (y <= 0);
But the effect is the same.
Upvotes: 9