
Signature
Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.
Hi Roedy,
You might want to also make it clear on your web page here:
# anonymous classes: unnamed inner class defined in the middle of a method.
# local classes: named inner class defined in the middle of a method.
The distinction between a local and anonymous class is not quite correct.
An anonymous class is a type of local class - the other type being a named
class.
Local class is to anonymous class as nested class is to inner class - one is
a more general type of the other.
Also, a method is not just the only context in which local classes can be
used.
Specifically, a method, constructor or initialiser are all possible contexts
of local (and therefore, anonymous) classes.
--
Tony Morris
http://tmorris.net/
Java Questions and Answers
http://jqa.tmorris.net/
> On Fri, 13 Jan 2006 09:37:55 -0600, Ian Pilcher
> <i.pilcher@comcast.net> wrote, quoted or indirectly quoted someone who
[quoted text clipped - 13 lines]
> Canadian Mind Products, Roedy Green.
> http://mindprod.com Java custom programming, consulting and coaching.
Chris Smith - 14 Jan 2006 06:05 GMT
> The distinction between a local and anonymous class is not quite correct.
> An anonymous class is a type of local class - the other type being a named
> class.
That's certainly an internally consistent use of terminology, but it is
not the same as the usage within the Java Language Specification...
which says:
§8
"This chapter discusses the common semantics of all classes -- top
level (§7.6) and nested (including member classes (§8.5, §9.5),
local classes (§14.3) and anonymous classes (§15.9.5))."
§14.3
"A local class is a nested class (§8) that is not a member of any
class and that has a name."
The first statement implies, and the second states outright, that an
anonymous class does NOT qualify as a "local class" in language spec
words. They certainly do share a lot of characteristics, though.

Signature
www.designacourse.com
The Easiest Way To Train Anyone... Anywhere.
Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation
Tony Morris - 13 Jan 2006 20:27 GMT
Tony Morris <not@telling.you> wrote:
> The distinction between a local and anonymous class is not quite correct.
> An anonymous class is a type of local class - the other type being a named
> class.
That's certainly an internally consistent use of terminology, but it is
not the same as the usage within the Java Language Specification...
which says:
§8
"This chapter discusses the common semantics of all classes -- top
level (§7.6) and nested (including member classes (§8.5, §9.5),
local classes (§14.3) and anonymous classes (§15.9.5))."
§14.3
"A local class is a nested class (§8) that is not a member of any
class and that has a name."
The first statement implies, and the second states outright, that an
anonymous class does NOT qualify as a "local class" in language spec
words. They certainly do share a lot of characteristics, though.
--
www.designacourse.com
The Easiest Way To Train Anyone... Anywhere.
Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation
Hello Chris,
I hadn't come across that section of the JLS. I can find other sections of
the JLS where there is clearly an implication that an anonymous class is a
local class, but certainly nothing as explicit as you mention. I put it down
to yet another contradiction in the JLS - and change my recommendation to
either stating the premise of the section of the JLS that you cite or change
the wording to avoid potential confusion.
I still think that it should not be explicitly stated that local/anonymous
classes are restricted to methods, since obviously, they are not.
Tony Morris
http://tmorris.net/
Java Questions and Answers
http://jqa.tmorris.net/