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.
Lew wrote:
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.
Lew wrote:
Your logic is utterly fallacious. ....
No one *in this newsgroup* has stepped up, so far. ...
Mike Schilling wrote:
In all the Apache or other open-source code I've read, I've never even
seem one. Have you?
Now, that is better logic.
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.
...
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?
I might now, given that they have already existed and I've been made
aware of them. If they had never existed, conceivably I might have
trouble imagining them.
It is harder to imagine things that never were and ask, "Why not?"
than to look at things as they are and ask, "Why?"
That they have been rarely used is not a compelling argument against
them, although it is indicative. Many features of Java are either
under-utilized or only suitable for rare use cases. But when you are
in those rare use cases, it's awfully handy to have that rarely-used
feature.
Personally, I like anonymous classes. The argument for named local
classes to me is that they are a better-self-documenting idiom than
anonymous classes, and suitable any place you'd have a method-scoped
anonymous class. If that anonymous class were better served as a
member class, then a local class wouldn't be an option. If that
anonymous class serves better than a member class, then a named local
class is a viable option.
--
Lew