title: Java: substituting a subclass/subtype of a parameter when overiding a method?
body: <p>So I asked this question before but I had a mistake in the code which most people picked up on, rather than the problem itself. </p>
  
  <p>Anyway, I'm trying to override an interface method in a class. However, I want the type of the parameter in the overriding method to be a subclass of the type of the parameter as defined in the overriden method.</p>
  
  <p>The interface is:</p>
  
  <pre><code>public interface Observer {
   public void update(ComponentUpdateEvent updateEvent) throws Exception;
  }
  </code></pre>
  
  <p>While the class that overrides this method is:</p>
  
  <pre><code>public class ConsoleDrawer extends Drawer {
  
  //...
  
   @Override
   public void update(ConsoleUpdateEvent updateEvent) throws Exception {
    if (this.componentType != updateEvent.getComponentType()) {
     throw new Exception("ComponentType Mismatch.");
    }
    else {
     messages = updateEvent.getComponentState(); 
    }
   }
  
  //...
  
  }
  </code></pre>
  
  <p>ConsoleUpdateEvent is a subclass of ComponentUpdateEvent. </p>
  
  <p>Now, I could just have the update() method in ConsoleDrawer take a ComponentUpdateEvent as a parameter and then cast it to a ConsoleUpdateEvent but I'm looking for a slightly more elegant solution if possible. Anyhelp would be appreciated. Thank you.</p>