Re: List or Iterator
Mike Schilling wrote:
I might as well make it a full-fledged nested class." Anyway, had
local classes never been invented, I doubt we'd miss them.
There was a reason why they were added to the Java language.
Obviously somebody missed them.
Mike Schilling wrote:
No one's stepped up and said "I created one, even once". So your
argument is that we'd miss something we don't use.
Your logic is utterly fallacious. That is not my argument, and I'll
thank you not to put words in my mouth.
No one *in this newsgroup* has stepped up, so far. That proves only
that no one in a particular limited population has used them, yet.
Given that how many readers here are still learning what nested
classes even are, let alone local classes, and that the readership
here is not a comprehensive, random or representative sample of Java
programmers, that proves exactly absolutely nothing except that many
of us are still learning.
In all the Apache or other open-source code I've read, I've never even
seem one. Have you?
One respondent has already provided valid scenarios where local
classes would be useful, e.g., as a cleaner way of doing things than
with anonymous classes. This doesn't prove anything either, but it
does point to the possibility that somebody would miss them. Also,
now that we're discussing local classes, there's a good chance that
someone who heretofore didn't know of the feature, as another
respondent has already admitted, will begin to do so.
For the record, my argument is that someone did find local classes
useful, oh, twelve or so years ago, since the powers that be went
through the trouble to add the feature to Java.
They were added at the same time as inner and anonymous classes, very
possibly because it seemed like a logical intermediate step between
the two, or even because they fell naturally out of the
implementation. Since then, they've hardly been used.
That is pretty strong
evidence that there was a use case for it, since an awful lot of
arguably useful features were not added to the language, yet that
made the cut early on. Is your argument that it was added even
no one felt a need for it? Or that they shouldn't have added it
because no one in a small group attached to a particular news group
twelve years later would see the value, or even be aware of the
I've also begun to see more value in the feature myself, now, and
to start to use it. A colleague of mine pointed out that the named
local class idiom is actually easier to read and more
than the anonymous class idiom. His arguments are strong, if not
overwhelming, and given the rampant ignorance around inner classes
Java generally, using such a thing to help readability is likely to
help maintainability of the code.
If local classes didn't exist and you had to make these member
classes, would you think "Geez, if only I could limit their scope by
defining them within a method.?" Honestly, would you?