title: how can i assign a closure class with a closure property
body: <p>I have a class something like this </p>
  
  <pre><code>class SomeClass () {
      Closure instClos
  
      SomeClass (Closure clos) { instClos = clos}  //constructor
  
      def call() {instClos()}
  }
  </code></pre>
  
  <p>what i'd like to be able to do is do implicit Class constructor like this </p>
  
  <pre><code> SomeClass myInst = {println "hello there}
   myInst()
  </code></pre>
  
  <p>but that doesn't work and throws cast exception.  you can make this work by writing [] round the closure to call the constructor.  but its not pretty</p>
  
  <pre><code>SomeClass myInst = [{println "hello there}]  // or myInst = new ({println "hello there}
  myInst()
  </code></pre>
  
  <p>is there a nice way to create the object through assignment and have that closure stored automatically on the created class instance?</p>
  
  <p>feel i'm missing some groovy syntax  here that would sort this  (PS i'd prefer not having to extend Closure if i can avoid that ) </p>
  
  <p>based on the input provided so far i provided an extended script to show the various options.  I tried to add an asType closure to Closure and try and call {...} as SomeClass - but if i tried that the asType is never called so groovy must be using another mechanism when you try a coercion</p>
  
  <pre><code>class SomeClass {
      Closure instClos
  
      SomeClass (Closure clos) {
          println "\tSomeClass constructor: Will constructor called"
          instClos = clos
      }
  
      def call() {
          println "\tSomeClass.call: calling closure "
          return (instClos() + "!")
      }
  
      SomeClass asType (Closure clos) {
          new SomeClass (instClos: clos)
      }
  }
  
  //this will call the map constructor - needs to be explicitly provided
  SomeClass me = [{println "map style construction"; "echo"}]
  assert me() == "echo!"
  
  //use new to get class instance with constructor
  me = new SomeClass ({println "new SomeClass () construction"; "echo"})
  assert me() == "echo!"
  
  //using layered closure approach - doesnt read well though
  def someClos = {new SomeClass(it)}
  def c = someClos {println "trying layered closure ";"echo"}
  assert c() == "echo!"
  
  //extending the Closure class to add a method
  ExpandoMetaClass.enableGlobally()
  Closure.metaClass.some =  {
      if (it ==  SomeClass) {
          new SomeClass (delegate)
      }
  }
  
  //this will call .some() on closure
  me = {println "hello will using .some() "; "echo"}.some ( SomeClass)
  assert me() == "echo!"
  </code></pre>