title: Different return types of abstract method in java without casting
body: <p>I am trying to implement and override a method with different return types without being forced to cast the return type.</p>
  
  <pre><code>public abstract class A {
  public abstract Object getValue(String content);
  }
  
  public class B extends A {
  public String getValue(String content) {...}
  }
  
  public class C extends A {
  public int getValue(String content) {...}
  }
  
  
  public class D extends A {
  public boolean getValue(String content) {...}
  }
  
  // Main loop:
  for (A a : allAs)
  {
  // I want to use the method getValue() and corresponding to the type return a String, int or boolean without casting the return type
  }
  </code></pre>
  
  <p>My question:
  Is it possible to return different types without being forced to cast?
  How has the abstract method look like to solve the problem?</p>
  
  <p>I think there has to be a solution because the compiler should know the return type...</p>