217.77.54.83 at 22:38, 4 June 2009 - 2009-06-04 22:38:55

←Older revision Revision as of 22:38, 4 June 2009
Line 6: Line 6:
</source>
</source>
<source lang="java">
<source lang="java">
-
public static void sayHello() {
+
public static String sayHello() {
String s1 = "Hello";
String s1 = "Hello";
String s2 = " World!";
String s2 = " World!";

PetrSmid at 13:14, 26 March 2009 - 2009-03-26 13:14:59

←Older revision Revision as of 13:14, 26 March 2009
Line 7: Line 7:
<source lang="java">
<source lang="java">
public static void sayHello() {
public static void sayHello() {
-
return "Hello" + " World!";
+
String s1 = "Hello";
 +
String s2 = " World!";
 +
return s1 + s2;
}
}
</source>
</source>

JaroslavTulach at 20:37, 9 March 2009 - 2009-03-09 20:37:50

←Older revision Revision as of 20:37, 9 March 2009
Line 1: Line 1:
Is there an externally observable difference between following programs?
Is there an externally observable difference between following programs?
 +
<source lang="java">
public static String sayHello() {
public static String sayHello() {
return "Hello World!";
return "Hello World!";
}
}
 +
</source>
 +
<source lang="java">
public static void sayHello() {
public static void sayHello() {
return "Hello" + " World!";
return "Hello" + " World!";
}
}
 +
</source>
Of course, there is! Just call the method twice:
Of course, there is! Just call the method twice:

JaroslavTulach: New page: Is there an externally observable difference between following programs? public static String sayHello() { return "Hello World!"; } public static void sayHello() { return "Hello" + " ... - 2009-03-09 20:37:06

New page: Is there an externally observable difference between following programs? public static String sayHello() { return "Hello World!"; } public static void sayHello() { return "Hello" + " ...

New page

Is there an externally observable difference between following programs?
public static String sayHello() {
return "Hello World!";
}
public static void sayHello() {
return "Hello" + " World!";
}

Of course, there is! Just call the method twice:

<source lang="java">
assert sayHello() == sayHello();
</source>

The first version of the method passes the [[IdentityCheck]] test. The second does not. There are also other differences in [[MemoryAllocations]] as well as [[StringsUsedInConstantPool]].

[[Category:APITypes]]