title: How to find container depth (eg:ArrayList<String>=1,ArrayList<ArrayList<String>>=2)?
body: <p>for example, in c++, I can find int=0,vector&lt; int >=1,vector&lt; &lt; vector&lt; int > >=2 by the following:</p>
  
  <pre><code>#include &lt;vector&gt;
  #include &lt;stdlib.h&gt;
  
  template &lt;typename T&gt;
  class Printer{
  public:
      static int print(){
          return 0;
      }
  };
  
  template &lt;typename T,typename Alloc&gt;
  class Printer&lt;std::vector&lt;T,Alloc&gt; &gt;{
  public:
      static int print(){
      return 1+Printer&lt;T&gt;::print();
      }
  };
  
  int main(){
      printf("%d\n",Printer&lt;int&gt;::print());
      printf("%d\n",Printer&lt;std::vector&lt;int&gt; &gt;::print());
      printf("%d\n",Printer&lt;std::vector&lt;std::vector&lt;int&gt; &gt; &gt;::print());
      return 0;
  }
  </code></pre>
  
  <p>which doesn't require any instance, for example:</p>
  
  <pre><code>std::vector&lt;int&gt; v;
  </code></pre>
  
  <p>to do that. How can I implement this function in Java? I tried:</p>
  
  <pre><code>public static void print(List&lt;Integer&gt; list){
  }
  
  public static &lt;T&gt; void print(List&lt;? extends T&gt; list) {
  }
  </code></pre>
  
  <p>and</p>
  
  <pre><code>public static &lt;T&gt;void print(){
  }
  
  public static void print() {
  }
  </code></pre>
  
  <p>but both says "both methods have same erasure". I also considered using if else like:</p>
  
  <pre><code>public static void print(Object obj) {
      if(obj instanceof List){
          List list=(List)obj;
          for(Object obj2 : list){
              print(obj2);
          }
      }else{
      }
  }
  </code></pre>
  
  <p>but I cannot get the type of element in the function. Is it possible to do this in Java?</p>