-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
nos wrote:
Does anyone know if the java compiler 1.4.2
from SUN optimizes subexpressions? I.e.
in the following two lines
int tcount =
Thread.currentThread().getThreadGroup().enumerate( myThreadList);
String tcurrent = Thread.currentThread().getName();
will it evaluate Thread.currentThread();
only once?
just curious
Hi,
I'm no expert, but I doubt the *compiler* could do that, since it
doesn't know that Thread.currentThread() doesn't have any
side-effects. It would have to make sure it gets called twice. After
all, it's theoretically (practically?) possible that the Thread
implementation could be replaced later with something that does have
side-effects. One possible place for such optimization would be a
highly-intelligent JIT, which "knows" about its own attached runtime
(i.e. it knows that Thread.currentThread() has no side-effects). I
don't think anything like this exists, though.
- --
Chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.2 (GNU/Linux)
iD8DBQE/rC3YwxczzJRavJYRApZmAJ48PgCVef/bVmx4AUeIuo9Uswbn9wCgwPPj
yqrDWpeTkDQFzLoi19FliRY=
=xmxk
-----END PGP SIGNATURE-----