问题描述:

boolean rhs;

rhs = value == null;

Specifically, the part I don't understand is the = operator followed by value followed by ==.

What does that mean?

网友答案:

Since comparing == has higher priority than = assigning, code

rhs = value == null;

is the same as

rhs = (value == null);

So it will check if value is null and store result of that test in rhs.

网友答案:

value == null is a boolean expression which evaluates to true if value == null, otherwise it is false. The value of this expression is assigned to rhs

The 2 statements are equivalent to

boolean rhs;
if (value == null)
   rhs = true;
else
   rhs false;
网友答案:

It is assigning to the boolean variable rhs the result of evaluating: value == null

网友答案:

This is the simple way to check whether the the value is null or not. If null then is will assign true to rhs, else false. You can try it by your self using following code:

    String value = null;
    String value2 = "Testing";
    boolean rhs;
    System.out.println(rhs=value == null); //print true
    System.out.println(rhs);

    System.out.println(rhs=value2 == null);//print false
    System.out.println(rhs);
相关阅读:
Top