This is my ternary condition in Java.
new_user_id.equals(userid) && new_key.equals(key) && !new_value.equals(value) ? updateValue() : System.out.println("New value already exists in DB");
I'm trying to match three conditions and call updateValue() function if all three conditions gets true. But still its throwing error "The left-hand side of an assignment must be a variable". Any ideas?
解决方案
The ternary operator is used for conditional variable assignment or something like:
System.out.println("You have " + items + (items == 1 ? "item." : "items."));
Therefore, it must return something. Use an if statement instead.