At 01:45 9/8/00 +0200, Uli Luckas wrote:
>Now the second bad news, if you decompile the code generated with either
>javac or jikes you can see that the constructor call is really compiled
>into the code.
umm... no it isn't....
test.java:
public class test {
public static void main (String[] args) {
String a = "aaa";
String b = new String("bbb");
System.out.println("---");
System.out.println(a);
System.out.println(b);
}
}
Jikes produced bytecode:
Method void main(java.lang.String[])
0 ldc #9 <String "aaa">
2 astore_1
3 new #11 <Class java.lang.String>
6 dup
7 ldc #13 <String "bbb">
9 invokespecial #18 <Method java.lang.String(java.lang.String)>
12 astore_2
13 getstatic #22 <Field java.io.PrintStream out>
16 ldc #25 <String "---">
18 invokevirtual #29 <Method void println(java.lang.String)>
21 getstatic #22 <Field java.io.PrintStream out>
24 aload_1
25 invokevirtual #29 <Method void println(java.lang.String)>
28 getstatic #22 <Field java.io.PrintStream out>
31 aload_2
32 invokevirtual #29 <Method void println(java.lang.String)>
35 return
as you can clearly see there is only one call to the String ctor,
and that is for b not a. Doing otherwise would be a violation of
the VM spec. Javac in 118 and 130 emit similar bytecode.
Jacob, another point I forgot to mention in my offlist reply was
that duplicating a String in java is potentially more than a byte
array copy... Strings have to be "internalized" which isn't always
cheap in either time or resources.
----------------------------------------------------------------------
To UNSUBSCRIBE, email to [EMAIL PROTECTED]
with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]