Recently I've been doing a lot of these
enum Thing {
/* etc etc */
static final Set<Thing> allThings = EnumSet.allOf(Thing.class);
}
I want something similar in pre 1.5 Java, i.e. I want something like:
final class Thing {
private Thing(); // control instances within class
static final Thing instance0 = new Thing();
static final Thing instance1 = new Thing();
static final Set allThings = // ?????
}
How should I do this?
What about that:
final class Thing {
static final Set allThings = new HashSet();
private Thing() {
allThings.add(this);
} // control instances within class
static final Thing instance0 = new Thing();
static final Thing instance1 = new Thing();
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With