Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
如何在java中创建一个对象的五个实例?
java - 如何在java中创建一个对象的五个实例,以便当引用该对象时,这五个实例应该像对象池?与单例模式一样,只有一个对象存在,应该有五个对象实例。
这基本上是枚举的定义:
public enum MyEnum { ONE, TWO, THREE, FOUR, FIVE }
一、二等是仅有的五个可能的实例MyEnum。
MyEnum