Not that I know of (but maybe there is and I don’t know it). Is it the
verbosity which bugs you, or that you have to construct the whole array
and then chuck it? You could do this instead:
BTW, you shouldn’t do this if you’re not certain that there will be
a PrototypesContainer which is a descendant of the module, as otherwise
calling next() on an interator for which !hasNext() will cause the world
to end.
This is on a newly created game module. Newly created game modules
always have a PrototypesContainer. I guess I could check this and
create one if there isn’t… I never really thought of that.
Is there a situation when a newly created module does not have a
PrototypesContainer? I’m regularly making assumptions about what’s
already there on a newly initialised module.
In general, I usually try to code defensively unless I’m certain that the
thing I’m looking for will exist. In particular, you’re dealing with code
I’ve never examined myself, so somebody else will have to tell you whether
there will always be a PrototypesContainer.
BTW Zoomer.java has compile errors under 1.5 compiler in eclipse. I had to remove the @Override tags from Zoomer.LevelModel.getElementAt() and Zoomer.LevelModel.getSize(). What is the purpose of the @Override tags anyway?
When creating a new module, BasicModule calls buildDefaultComponents() which will ensure that a PrototypesContainer exists.
When opening an old module, BasicModule calls ensureComponent(Class<?>) to make sure certain components exist, but PrototypesContainer is not one of these (GamePieceImageDefinitions, GlobalProperties and Language). So potentially, opening a very old module may result in a module without a PrototypesContainer.
The @Override tag is to indicate that you’re intending to override a
method from the superclass. The idea is that you’ll get an error if
you have a method marked @Override in case it doesn’t succeed in
overriding anything. E.g., if you left out an arugment or had a double
instead of an int, and didn’t have an @Override tag then you’d get no
indication from the compiler that something was wrong.
Looking back, those two methods aren’t actually implemented in
AbstractListModel—it inherits them from the ListModel interface. It
appears that Eclipse’s compiler is stricter about what can be marked @Override than the standard Java compiler is.