title: Can I override cast operator in Groovy?
body: <p>I need something as similar as possible to this:</p>
  
  <pre><code>interface Bar { 
      def doSomething()
  }
  
  class Foo { // does not implement Bar.
  
      def doSomethingElse() {
      }
  
      Bar asBar() { // cast overload
          return new Bar() {
              def doSomething() {
                  doSomethingElse()
              }
          }
      }
  
  }
  
  Foo foo = new Foo()
  Bar bar = foo as Bar
  bar.doSomething()
  </code></pre>
  
  <p>Is there something like this in Groovy?</p>