Instantiation new variable

Hi,

I have a simple example where I instantiate a new variable

into a while loop.

while (exp){

String str =new String ("Hello World!");

}

that is different from

String str;

while (exp){

str =new String ("Hello World!");

}

If I use the first code this is translated into the second.

This translation is made by Java Compilator because the second way

is better run-time.

But if I compile the first code and than I decompile the .class file I find

the first code and not the code translated by compilator. Why?

[895 byte] By [enrico.classa] at [2007-11-27 11:23:22]
# 1

> I have a simple example where I instantiate a new

> variable

> nto a while loop.

You instantiate a new String. Variables are declared.

> If I use the first code this is translated into the second.

Both are translated into something else that does variable definitions for a method first.

> This translation is made by Java Compilator because

> the second way

> is better run-time.

BS. Makes no difference.

> But if I compile the first code and than I decompile

> the .class file I find

> the first code and not the code translated by

> compilator. Why?

Because, as I said, both are transformed into the same instructions.

And never use "new String("...")" if you don't have a good reason. Although I feel like it was wanted here.

CeciNEstPasUnProgrammeura at 2007-7-29 15:00:19 > top of Java-index,Java Essentials,Java Programming...