Created
October 25, 2013 10:16
-
-
Save ssmiech/7152515 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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