title: Common Interface with Different Return Types [Java]
body: <p>I'm trying to implement the <code>Command</code> pattern in various classes by extending/implementing the <code>Command</code> class which contains a single method <code>public void execute()</code>. However, down the line I noticed I need to implement a number of variations of the pattern to allow it to return different values such as <code>boolean</code> and other custom values. I would like all these classes to inherit/implement a single common interface that requires them to implement the method execute() (and perhaps several other methods) while giving each class the flexibility to add its own return type.</p>
  
  <p>First I thought I could accomplish this with generics but this would not work - as it does not enforce the return type in the sub classes (it would allow for any return type).</p>
  
  <p>Tech, I could create many "Command" classes (such as <code>BooleanCommand</code> + <code>StringCommand</code> + several other such classes with custom return types) but this would mean I need to design each class from scratch as they are not implementing a common interface. In other words, there's no way for me to have <code>BooleanCommand</code> implement the base class <code>Command</code> thereby forcing it to implement the method <code>execute()</code> while allowing it to have it's own return value of <code>boolean</code>. Similarly, I would like the <code>StringCommand</code> class to implement the base class <code>Command</code>  (thereby forcing it to implement the method <code>execute()</code> ) while allowing it to have <code>String</code> as a return value.</p>
  
  <p>This might be fine if I had only one method in each class but what if I have several methods and no way to enforce this design?</p>
  
  <p>How can I solve this design issue?</p>