内容
以下の設定をテンプレートに追加する。
名前:fluent
説明:流れるようなIF形式のSetter
パターン
/**
* {@code ${name}}を設定し、自クラスのインスタンスを返却する.
*
* @param ${name} ${name}
* @return 自クラスのインスタンス
**/
public ${enclosing_type} ${name}(${type} ${name}){
this.${name} = ${name};
return this;
}
サンプルコード
package sample; public class SampleFluent { private String hoge; public static void main(String[] args) { SampleFluent hoge2 = new SampleFluent().hoge("hoge"); System.out.println(hoge2.hoge); } // テンプレートで生成した箇所 開始 /** * {@code hoge}を設定し、自クラスのインスタンスを返却する. * * @param hoge hoge * @return 自クラスのインスタンス **/ public SampleFluent hoge(String hoge) { this.hoge = hoge; return this; } // テンプレートで生成した箇所 終了 }