title: Java: Curious ImmutableList add
body: <p>I don't understand this method implementation. It's </p>
  
  <pre><code>public static &lt;T&gt; List&lt;T&gt; add(List&lt;T&gt; list, T element) {
      final int size = list.size();
      if (size == 0) {
          return ImmutableList.of(element);
      } else if (list instanceof ImmutableList) {
          if (size == 1) {
              final T val = list.get(0);
              list = Lists.newArrayList();
              list.add(val);
          } else {
              list = Lists.newArrayList(list);
          }
      }
      list.add(element);
      return list;
  }
  </code></pre>
  
  <p>Why not a straightforward <code>list.add(element)</code>?</p>