title: Type safety: Potential heap pollution via varargs parameter subtrees
body: <p>I'm reading J. Bloch's effective Java and I got that unchecked casts is never good unless we made sure that the cast is safe. Now, since Java Collection frameworks doesn't provide us with <code>Tree</code> data structure I have to write on my own.</p>
  
  <pre><code>public interface TreeVisitor&lt;E, R&gt; {
      public R visit(E leaf);
  
      public R visit(E val, Tree&lt;E&gt;... subtrees);
  }
  
  public abstract class Tree&lt;E&gt; {
  
      public abstract &lt;R&gt; R accept(TreeVisitor&lt;E, R&gt; visitor);
  
      public Tree&lt;E&gt; leaf(E leaf) {
          return new Tree&lt;E&gt;() {
              @Override
              public &lt;R&gt; R accept(TreeVisitor&lt;E, R&gt; visitor) {
                  return visitor.visit(leaf);
              }
          };
      }
  
      public Tree&lt;E&gt; branch(E value, Tree&lt;E&gt;... subtrees){ //1
          return new Tree&lt;E&gt;(){
              @Override
              public &lt;R&gt; R accept(TreeVisitor&lt;E, R&gt; visitor) {
                  return visitor.visit(value, subtrees);
              }
          };
      }
  
  }
  </code></pre>
  
  <p>At <code>//1</code>, I got the warning:</p>
  
  <blockquote>
    <p>Type safety: Potential heap pollution via varargs parameter subtrees</p>
  </blockquote>
  
  <p>How can I check that my code actually safe?</p>