Java Singleton Pattern

后端 未结 8 1865
难免孤独
难免孤独 2020-12-03 05:22

Edit: Answered - error was method wasn\'t static

I\'m used the Singleton Design Pattern

 public class Singleton {
   private static final Singleton I         


        
8条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-03 05:59

    This one:

     Singleton singleton = Singleton.getInstance();
    

    should work. This is how you call static methods in Java. And the getInstance() method is declared as static. Are you sure you are using the very same Singleton class? Or maybe you have imported a class called the same in some other package.

提交回复
热议问题