My good friend Greg mentioned that I should use bitwise operators to perform a toggle, as opposed to my earlier method of using integer math to manipulate the state . I had not done that because the bitwise implementation is imho not comprehensible by a developer who does not have a CS degree. As an example it is not at ALL clear to most people that ~2<<10 != ~(2<<10) Although I suppose that's the point of a method name. /**
* A simple way to implement a toggle switch using an integer to store the state
* and bitwise operators to manipulate the toggle
*
* @author Dan Fishman http://www.fishdan.com
*
* This code released to the public under the CreativeCommons 3.0 license by
* the author on 8/21/2011
*
* http://creativecommons.org/licenses/by/3.0/
*/
public class TestToggle {
public static int toggleState=0;
public static void main(String argv[]){
for ( int x=0;x<32;x++){
...
a personal and public white board