Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8142440

String folding stops when a non-constant object is reached

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Unresolved
    • Icon: P4 P4
    • tbd
    • 9
    • tools

      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".

            mcimadamore Maurizio Cimadamore
            shade Aleksey Shipilev
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: