title: Generic Return type : How to catch a return type from many possible return types?
body: <p>Writing the title was a bit tricky for this question :p<br><br>
  This is a basic java query!<br>
  I am using google cloud and it has different methods, such as launchInstance, listInstances and terminateInstance and so on.. Here, launchInstance will return a type String as Success or Fail, listInstances will return ArrayList, and so forth.</p>
  
  <p>Now, I want a generic return type, so I made a class which has data entries such as status, reason, and dataRequired which will eventually send the data that is required, i.e String or ArrayList or HashMap.
  How can I achieve this functionality.
  Here is sample code that I was thinking of doing:</p>
  
  <pre><code>public class ResponseHelper {
  
      private String status;
      private String reason;
      private String type;
      private Object data;
  
      public String getStatus() {
          return status;
      }
      public void setStatus(String status) {
          this.status = status;
      }
      public String getReason() {
          return reason;
      }
      public void setReason(String reason) {
          this.reason = reason;
      }
      public String getType() {
          return type;
      }
      public void setType(String type) {
          this.type = type;
      }
  
      public void dataRequired(Object data) {
          switch(getType()) {
          case "ArrayList": this.data=(ArrayList&lt;String&gt;)data;
  
          }
  
      }
  
  }
  </code></pre>