title: How to make string with fragments from different strategies static?
body: <p>When we concatenate compile-time static Strings using the <code>+</code> operator, the compiler will join them together and store a new static string in its place.</p>
  
  <p>Now I have a strategy pattern that supplies SQL fragments that should be concatenated into a larger SQL statement. All the pieces are static, but since there are method calls involved the above compile-time joining does not happen.</p>
  
  <p>Example:</p>
  
  <pre><code>class MagicDao {
      void Object daoMethod(GetStuff cmd) {
          String sql = "select ... where " + cmd.getWhereClause() + " order by ...";
          // ...
      }
  }
  
  public interface GetStuff {
      String getWhereClause();
  
      Object[] getParameters();
  }
  
  class GetFunStuff implements GetStuff {
      public String getWhereClause() {
          return " abc = ? ";
      }
  
      // ...
  }
  </code></pre>
  
  <p>I am wondering is there any pattern/trick that will make the SQL string concatenation compile-time again while retaining the simplicity/readability of the code above.</p>
  
  <p>(If caching is the only solution, could one suggest a readable, thread-safe one liner?)</p>
  
  <p>(Motivation for doing this: making things static will save countless garbage being created each second during the string building process and saves the time looking up the string in the <code>PreparedStatement</code> cache.)</p>