0

ここでGroovy DSL Docのコードを変更した場合。

このように、文字列「hello world」をメールに追加します

email('hello world') { // change here
   from 'dsl-guru@mycompany.com'
   to 'john.doe@waitaminute.com'
   subject 'The pope has resigned!'
   body {
      p 'Really, the pope has resigned!'
   }
}

変更する

def email(def name, @DelegatesTo(EmailSpec) Closure cl) {  // change here
    def email = new EmailSpec()
    def code = cl.rehydrate(email, this, this)
    code.resolveStrategy = Closure.DELEGATE_ONLY
    code.call(name) // change here
}

では、クラス EmailSpec を変更して文字列「hello world」を取得する方法は??

4

2 に答える 2

0

はい、方法は見つかりましたが、完璧ではありません。

単純

new EmailSpec(name)  // change to 

しかし、私は本当にそれを解決するためにgroovy function call(name)を使いたいです

于 2016-06-14T06:08:30.087 に答える