boolean canDelegate = AFSession.get() .currentUser() .getSubstituteOf() .contains(participant) && (reply == null ? false : reply.getPublishTime() != null); - Try to remove) probably not needed - user31238
- but will it not be without brackets to consider the verifiable condition of the ternary operator completely from assigning a variable to "?" ? type boolean canDelegate = (AFSession.get (). currentUser (). getSubstituteOf (). contains (participant) && reply == null)? (false): (reply.getPublishTime ()! = null); - Hex Hex Hex
- Yes, brackets are needed - user31238
|
1 answer
The priority table clearly indicates that operator priority == higher than the ternary operator. It can also be confirmed by practical consideration:
System.out.println(1 == 2 > 1 ? 2 : 1); We get an error of incompatible types.
That is, first the statement > in the expression 2 > 1 executed.
Then the operator == executed in the expression 1 == true , which caused the error.
That is the answer: yes, brackets are needed.
|