title: Passing dynamic class objects in Java
body: <h2>What's the best approach to pass dynamic class objects as parameters ?</h2>
  
  <p>My use case is something like this,</p>
  
  <p>I have a common network class that performs network operations based on the given type and then converts the response into a pojo class. Here's a demo,</p>
  
  <pre><code> public abstract class CommonOperations {
  
       public void getAuthToken() {
       ......
       AuthToken authToken = response.body();
       success(authToken);
      }
  
       public void performLogin() {
       ......
       Login login = response.body();
       success(login);
      }
  
      }
  
   public abstract void success(Object object);
  </code></pre>
  
  <p>Later, I would like to receive the dynamic object from the overriden class.</p>
  
  <p>e.g. </p>
  
  <pre><code>@Override
   public void success(Object requestedObject) {
  
   AuthToken authToken = (AuthToken) requestedObject;
  
  }
  </code></pre>
  
  <p>or </p>
  
  <pre><code>@Override
   public void success(Object requestedObject) {
  
   Login login = (Login) requestedObject;
  
  }
  </code></pre>
  
  <hr>
  
  <p>Is there any way to achieve this in Java?  </p>
  
  <p>I found some similar solutions based on Java Generics and Reflection but I am not sure how to apply it in this context. </p>