简体   繁体   中英

Why singleton getInstance method has to be public static in Java

I am just curious why a Singleton class getInstance (or whatever you want to call it) needs to be public static. It only needs to be static not public if that singleton should only be used with in the same package or is my assumption is incorrect.

If you don't need it public, don't make it public!

As long as you can use it where you need it you'll be fine.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM