辛格尔顿:什么是更好的选择?

时间:2017-01-12 06:58:21

标签: java singleton

方法1

 public static synchronized Database getInstance(){
   if(INSTANCE == null){
     INSTANCE = new Database();
   }
   return INSTANCE;
}

方法2

private static final Database INSTANCE = new Database();
    public static Database getInstance(){
        return INSTANCE;
    }

哪个是更好的选择?

0 个答案:

没有答案