I am making a game, and don't want someone to be able to add another instance of an object. How would I do this?
protected void addedToWorld(World w)
{
if (w.getObjects(ClassName.class).size() > 1)
{
w.removeObject(this);
}
}
class Singleton {
private static Singleton instance;
private Singleton(){}
public static Singleton getInstance() {
if(instance == null) {
instance = new Singleton();
}
}
}