ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
~~~ public class Person { // 类初始化时,会立即记载该对象,线程安全,调用效率高 private static Person p = new Person(); private Person(){ System.out.println("Person 初始化"); } public static Person getInstance(){ System.out.println("get person instance"); return p; } } ~~~ ~~~ public static void main(String[] args) { Person p1 = Person.getInstance(); Person p2 = Person.getInstance(); System.out.println(p1 == p2); } ~~~