1:.经典懒汉: 代码如下: package org.pine.test; public class Person { private String name; private int age; public static Person person; private Person(){ } public int getAge() { return age; } public void setAge(int age) { this.age = age; } public String getNa…
java单例的几种实现方法: 方式1: public class Something { private Something() {} private static class LazyHolder { private static final Something INSTANCE = new Something(); } public static Something getInstance() { return LazyHolder.INSTANCE; } } 方式2: public cla…