In article <3b1f662d.133267248@news.cis.dfn.de>,
Jonathan.Cunningham@tesco.net (Jonathan L Cunningham) writes:
> On 31 May 2001 12:56:17 GMT, kers@hplb.hpl.hp.com () wrote:
>
>>In article <9f5avq$9ls$1@soapbox.cs.bham.ac.uk>,
>> Aaron.Sloman.XX@cs.bham.ac.uk
>> (Aaron Sloman See text for reply address) writes:
>>
>>> I don't know how anonymous classes work in Java,
> (snip)
>>> (b) efficiency because global identifiers don't need to be created
>>
>>Certainly not true for Java classes!
>
> Is that right?
For suitable values of the term "global identifier".
> I don't know what the output of a Java compiler looks like,
It's a class file, as documented in the JVM spec. It's *not* that hard
to parse, it turns out (working with the result, that's different).
> and you do say
>
>>I'm not sure the existing language design and implementation constraints
>>(eg it must compile to code that works on the older JVMs) left them
>>much room for manoeuver).
>
> so I can believe it, but it is not obvious that an anonymous class
> would need a global identifier, so I may be misreading an ambiguity
> in what you wrote.
JVM classes all have names. There's no way to express in the class-file
a class that has no name. The compiler *generates* a name for the class:
if class ``Legs` is nested inside a class called `Spoo`, then the class
is given the "global name" `Spoo$Legs`.
[A Java program cannot utter such a name, but that's no big deal given
the ability to hack classfiles.]
Recall that each class gets its own classfile (I kid thee not), and
classfiles have to be fetched by name, so getting a class without a name
would be ... interesting.
> (Or, to put that another way, I bet it is possible to for a
> sufficiently clever Java compiler to avoid generating a global name,
> for sufficiently large values of "sufficiently clever" :-).
The translation rules are mandated by the specification, if I recall
correctly, so such a compiler would be non-conforming. I think "cleverness"
blends into "psychic" at this point. We need a quantum compiler.
--
Chris "electric hedgehog" Dollin
C FAQs at: http://www.faqs.org/faqs/by-newsgroup/comp/comp.lang.c.html
|