Created
June 13, 2024 05:32
-
-
Save jaimemin/1ff3810f3c48b2d7d7db07f752cf69ec 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
| Settings settings = Settings.getInstance(); | |
| /** | |
| * 리플렉션을 통해 싱글턴 패턴 깨트릴 수 있음 | |
| * 단, enum일 경우 깨트릴 수 없음 | |
| * Cannot reflectively create enum objects | |
| */ | |
| Constructor<Settings> constructor = Settings.class.getDeclaredConstructor(); | |
| constructor.setAccessible(true); // private 생성자이기 때문에 setAccessible(true) | |
| Settings settingsGeneratedByReflector = constructor.newInstance(); | |
| System.out.println(settings == settingsGeneratedByReflector); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment