title: How to get (int) values from POJO class object using JAVA generic
body: <p>I have below piece of code which is going to get the value from given array list irrespective of data type. And It works fine.</p>
  
  <pre><code>   public static &lt;E&gt; void getAll(List&lt;E&gt; elements) 
      {
          for (E el : elements) 
          {
              System.out.println(el.toString());
          }
          System.out.println();
      }
  
      public static void main(String args[]) throws Exception 
      {
          List&lt;Integer&gt; listInt = new ArrayList&lt;Integer&gt;();
          listInt.add(3);
          listInt.add(4);
          listInt.add(5);
          listInt.add(6);
  
          List&lt;String&gt; listStr = new ArrayList&lt;String&gt;();
          listStr.add("Animal");
          listStr.add("Ball");
          listStr.add("cat");
          listStr.add("dog");
  
          getAll(listInt);
          getAll(listStr);
      }
  </code></pre>
  
  <p><strong>Output:</strong></p>
  
  <pre><code>3
  4
  5
  6
  
  Animal
  Ball
  cat
  dog
  </code></pre>
  
  <p>But I tried the same concept to get the data from POJO object but Its fail and return only object instead of Field as look like above.</p>
  
  <p>The below code is my sample POJO:</p>
  
  <pre><code>  public class Test1 
    {
  
      private String car;
      private int price;
  
      public String getCar() 
      {
          return car;
      }
  
      public void setCar(String car) 
      {
          this.car = car;
      }
  
     public int getPrice() 
     {
      return price;
     }
  
     public void setPrice(int price) 
     {
      this.price = price;
     }
     public String toString() 
     {
      return String.format(car);
     }
  
    }
  </code></pre>
  
  <p>The below code is added into main() method:</p>
  
  <pre><code>     Test1 t1 = new Test1();
       t1.setCar("volvo");
       t1.setPrice(400000);
  
       Test1 t2 = new Test1();
       t2.setCar("datsun");
       t2.setPrice(500000);
  
       List&lt;Test1&gt; t1Array = new ArrayList&lt;Test1&gt;();
       t1Array.add(t1);
       t1Array.add(t2);
  
       getAll(t1Array);
  </code></pre>
  
  <p>And below is the output of the code:</p>
  
  <p><strong>Output:</strong></p>
  
  <pre><code> Volvo
   Datsun
  </code></pre>
  
  <p>Is there any other way to get the value (Integer) of the field, which will works for any type of POJO class.</p>
  
  <p>Any leads?</p>