title: Cast any Map to custom type
body: <p>I'm trying to find a way to cast <strong>any</strong> <em>Map</em> to instance of my class <em>A</em> using "as" operator.in Groovy, like this:</p>
  
  <pre><code>import java.util.concurrent.ConcurrentHashMap;
  class A { 
      def list = new ArrayList();
      A( Map map ) {
          for( e in map.entrySet() ) {
              list.add( e.getKey );
              list.add( e.getValue() );
          }
      }
  };
  def map = [ key1 : 'value1', key2 : 'value2' ] as ConcurrentHashMap;
  def instA = map as A;
  assert instA.list.containsAll( [ 'key1', 'value1', 'key2', 'value2' ] );
  </code></pre>
  
  <p>This is a hypothetical example, but it shows the essence of the problem.</p>