title: Does Groovy allow generic object casting for abstract method attributes?
body: <p>I want to force all Command objects that manage communicating Domain objects in the MVC to implement a setData method for their respective domain objects.</p>
  
  <p>So, let's say it is given: </p>
  
  <pre><code>class User { //this is a domain
     Long id
     String userName
  }
  </code></pre>
  
  <p>And base command:</p>
  
  <pre><code>abstract class DomainObjectCommand {
      ...
  
      abstract setData(Object domain)
  
      ...
  } 
  </code></pre>
  
  <p>And finally, the actual command object we will use:</p>
  
  <pre><code>class ListUserCommand extends DomainObjectCommand {
  
      Long userId
      String userName
  
      public setData( User user ) { //this is not a valid implementation of the abstract method because "Object" is not "User"
        ...
      }
  }
  </code></pre>
  
  <p>Is there a <em>graceful</em> way to do this? </p>
  
  <p>I want to be certain all command objects behave similarly in the way domain data is set in the command, but obviously each command will have its own unique domain object it must manage so the abstract method needs to allow for <strong>any</strong> domain object, not just User or Role or whatever it might be. </p>
  
  <p>For now, I simply stopped the "enforcement" by implementing a base method and throwing a basic exception:</p>
  
  <pre><code>public setData(Object domain) {
      throw new NotImplementedException()
  }
  </code></pre>