I am trying to write a method that when invoked, changes a boolean variable to true, and when invoked again, changes the same variable to false, etc.
For example: ca
private boolean negate(boolean val) {
return !val;
}
I think that is what you are asking for??
value ^= true;
That is value xor-equals true, which will flip it every time, and without any branching or temporary variables.
Without looking at it, set it to not itself. I don't know how to code it in Java, but in Objective-C I would say
booleanVariable = !booleanVariable;
This flips the variable.