-
Enhancement
-
Resolution: Unresolved
-
P4
-
9
Even after JDK-8134007, it seems javac only folds String-like constants from left to right, and it breaks as soon as non-constant is reached. See e.g.:
public class StaticStringConst {
static final int INT = 42;
static final Object OBJ = new Object();
static final String STR = "Foo";
public static String m1() {
return "" + INT + STR + OBJ;
}
public static String m2() {
return "" + STR + INT + OBJ;
}
public static String m3() {
return "" + OBJ + INT + STR;
}
public static String m4() {
return "" + OBJ + STR + INT;
}
}
m1() folds nicely to "42Foo" + OBJ, but m2() folds only to OBJ + 42 + "Foo".
public class StaticStringConst {
static final int INT = 42;
static final Object OBJ = new Object();
static final String STR = "Foo";
public static String m1() {
return "" + INT + STR + OBJ;
}
public static String m2() {
return "" + STR + INT + OBJ;
}
public static String m3() {
return "" + OBJ + INT + STR;
}
public static String m4() {
return "" + OBJ + STR + INT;
}
}
m1() folds nicely to "42Foo" + OBJ, but m2() folds only to OBJ + 42 + "Foo".
- relates to
-
JDK-8134007 Improve string folding
- Closed