Skip to content

Instantly share code, notes, and snippets.

@jaimemin
Created June 13, 2024 05:32
Show Gist options
  • Save jaimemin/1ff3810f3c48b2d7d7db07f752cf69ec to your computer and use it in GitHub Desktop.
Save jaimemin/1ff3810f3c48b2d7d7db07f752cf69ec to your computer and use it in GitHub Desktop.
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