0
boolean rhs; rhs = value == null; 

Specifically, the part I don't understand is the = operator followed by value followed by ==. What does that mean?

3
  • 1
    if value equal to null assign true/false to rhs Commented Oct 18, 2013 at 2:38
  • 1
    Look for "operator precedence", and you will understand that statement. Commented Oct 18, 2013 at 2:39
  • Think of it like if (value == null) rhs = true; else rhs = false, but just shorter... Commented Oct 18, 2013 at 2:44

4 Answers 4

10

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.

Sign up to request clarification or add additional context in comments.

Comments

3

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; 

Comments

1

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

Comments

0

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); 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.