Java-JVM 类的初始化
Posted 8932809
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Java-JVM 类的初始化相关的知识,希望对你有一定的参考价值。
public class Test { protected static final Logger logger = LoggerFactory.getLogger(Test.class); public static void main(String[] args) { Singleton singleton = Singleton.getInstance(); logger.info("counter1:" + singleton.counter1); logger.info("counter2:" + singleton.counter2); } } class Singleton { private static Singleton singleton = new Singleton(); public static int counter1; public static int counter2 = 0; private Singleton() { counter1++; counter2++; } public static Singleton getInstance() { return singleton; } }
以上是关于Java-JVM 类的初始化的主要内容,如果未能解决你的问题,请参考以下文章