title: What's the preferred Java convention for naming static constructor methods
body: <p>What is the preferred convention for naming static constructor methods? For example, say I have an <code>Error</code> class, which has a single constructor which simply initialises the fields, and then some static constructor methods:</p>
  
  <pre><code>class Error {
      static Error xxxx(String msg) {
          return new Error(msg, -1);
      }
  
      static Error xxxx(String msg, int line) {
          return new Error(msg, line);
      }
  
      final String msg;
      final int line;
  
      private Error(String msg, int line) {
          this.msg = msg;
          this.line = line
      }
  }
  </code></pre>
  
  <p>What should I name the <code>xxxx</code> methods. Possibilities include:</p>
  
  <ol>
  <li><code>valueOf</code> - some Java classes follow this, e.g. <code>Integer.valueOf</code>, but is this only used for boxing primitives?</li>
  <li><code>of</code> - more terse. <code>Error.of(msg, i)</code> seems readable.</li>
  <li><code>error</code> - some pros and cons - see below.</li>
  <li><code>create</code> - gives undue emphasis to the mechanism (create something) instead of the intent (give me a value). For instance, some implementations may cache and re-use values, meaning something isn't always actually created as such.</li>
  <li><code>createError</code> - wordy, and same issue as <code>create</code>.</li>
  </ol>
  
  <p>I tend to code in a functional style, and, possibly as a consequence, my preference was #3, partly because if I static import <code>Error</code> then I can call it simply as <code>error(msg, i)</code>, which seems readable and mimics actual constructor usage. However, it may cause confusion with local variables of the same name. For example <code>error = error(msg, i);</code> looks confusing.</p>
  
  <p>I would be interested in seeing evidence or arguments in favour of a particular approach, rather than simple "I like xxx" answers.</p>