IdentityCheck

From APIDesign

(Difference between revisions)
Jump to: navigation, search
(New page: Is there an externally observable difference between following programs? public static String sayHello() { return "Hello World!"; } public static void sayHello() { return "Hello" + " ...)
Current revision (22:38, 4 June 2009) (edit) (undo)
 
(2 intermediate revisions not shown.)
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!";
}
}
-
public static void sayHello() {
+
</source>
-
return "Hello" + " World!";
+
<source lang="java">
 +
public static String sayHello() {
 +
String s1 = "Hello";
 +
String s2 = " World!";
 +
return s1 + s2;
}
}
 +
</source>
Of course, there is! Just call the method twice:
Of course, there is! Just call the method twice:

Current revision

Is there an externally observable difference between following programs?

public static String sayHello() {
  return "Hello World!";
}
public static String sayHello() {
  String s1 = "Hello";
  String s2 = " World!";
  return s1 + s2;
}

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

assert sayHello() == sayHello();

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.

Personal tools
buy