>
> Godmar Back wrote,
> > Miles Sabin wrote,
> > > [snip: className.class vs Class.forName("className")]
> >
> > In other words, you're saving a try/catch clause at the
> > expense of one hidden static variable.
>
> Hmm ... well, a litte more than that. The lookup is done
> only once (to initialize the static).
Fair enough. An experienced programmer would probably include
such a guard as well.
>
> Still, I have to admit I was a bit surprised at the
> generated bytecode. I'd assumed that the constant pool
> would contain a reference to the class which would be resolved directly by
> the JVM at load time, rather by
> code at the first point of use.
>
> Is this just a compiler artefact (I've checked both
> jikes and javac from 1.2.2) or is there some intrinsic
> reason why it has to be done this way? I haven't been
> able to find anything obvious that bears on this in
> either the JLS or the JVM spec. I suppose it might allow
> some class loading to be deferred or eliminated ... is
> that the rationale?
>
One reason might be that there's no bytecode instruction in the
JVM's bytecode instruction set to load a java.lang.Class ref from the
constant pool.
- Godmar
----------------------------------------------------------------------
To UNSUBSCRIBE, email to [EMAIL PROTECTED]
with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]