title: Java method with generic return Type
body: <p>Is there a way in Java to return different types with one declaration of a method?</p>
  
  <pre class="lang-java prettyprint-override"><code>public Object loadSerialized(String path) {
      Object tmpObject;
  
      try {
          FileInputStream fis = new FileInputStream(path);
          ObjectInputStream ois = new ObjectInputStream(fis);
          tmpObject = (Object) ois.readObject();
  
          ois.close();
          fis.close();
  
          return tmpObject;
      } catch (FileNotFoundException e) {
          return null;
      } catch (Exception e) {
      }
  }
  </code></pre>
  
  <p>I want this method to return an Object and I cloud cast it to the right type at the function call. That was what i thought but it doesn't work like this. Do I need some kind of generic return Type to do this?
  What would be the best way to solve this problem?</p>