The constructor can check:
public class OnlyOne {
static count = 0;
public OnlyOne() {
if (count > 0) throw ...
count++;
...
}
}
or a factory method:
public class OnlyOne {
static count = 0;
public static OnlyOne make() {
if (count > 0) throw ...
count++;
return new OnlyOne();
}
private OnlyOne() { ...}
}
Update: Ideally, creation of this class would be so simple, e.g., when program starts and then passed as dependency, that this check would unnecessary. But if creation happens in a more complex situation, as I assume yours is, then it's a useful safety check.