什么时候在Java中初始化类变量?

时间:2019-02-23 11:46:45

标签: java static singleton

我正在学习Singleton模式,我想问你什么时候才初始化类变量?

例如,我有以下代码:

           if (err) {
                reject(err)
            }
            else {
                if (results === undefined) {
                    reject(new Error("Error rows is undefined"));
                }

演示类:

           if (err) {
                console.log(err)
            }
            else {
                if (results === undefined) {
                    reject(new Error("Error rows is undefined"));
                }

public class EagerInitializedSingleton { private static final EagerInitializedSingleton instance = new EagerInitializedSingleton(); private EagerInitializedSingleton() { } public static EagerInitializedSingleton getInstance() { return instance; } } 变量何时准确初始化?何时调用getInstance()方法?

0 个答案:

没有答案