Re: List or Iterator
Lew wrote:
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's what I mean by "not missing them". There are a few places I'd
like to be able to scope things more closely [1], but allowing an
inner class to be used by only one method has never been one of them.
If it weren't possible, it would never occur to me to ask for it.
1. One example: sometimes I'd like to be able to declare that a
private field can only be seen by certain methods, e.g. to force the
use of an accessor even within the declaring class.