Skip to content

Instantly share code, notes, and snippets.

@ssmiech
Created October 25, 2013 10:16
Show Gist options
  • Save ssmiech/7152515 to your computer and use it in GitHub Desktop.
Save ssmiech/7152515 to your computer and use it in GitHub Desktop.
package test;
public class Test {
public static final Empty EMPTY = new Empty();
public static void main(String[] args) {
// first test instantiates the Empty class
Empty first_test = EMPTY;
System.out.println(String.format("inFirst test before changing state: %b", first_test.isLoading()));
// first test sets the state
first_test.setState();
// now second test does not instantiate anymore, the EMPTY is static final, and already created
// it just returns previously created instance of Empty class with poluted state.
Empty second_test = EMPTY;
System.out.println(String.format("sec_test, state should be false but is: %b", second_test.isLoading()));
}
}
package test;
public class Empty {
private boolean mState = false;
public boolean isLoading() {
return mState;
}
public void setState() {
mState = true;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment