有沒有什麼辦法可以在IntelliJ中自動編寫生成器模式?IntelliJ中生成器模式代碼生成
例如,假定這個簡單的類:
class Film {
private String title;
private int length;
public void setTitle(String title) {
this.title = title;
}
public String getTitle() {
return this.title;
}
public void setLength(int length) {
this.length = length;
}
public int getLength() {
return this.length;
}
}
是有辦法,我能得到IDE產生這種或類似:
public class FilmBuilder {
Film film;
public FilmBuilder() {
film = new Film();
}
public FilmBuilder withTitle(String title) {
film.setTitle(title);
return this;
}
public FilmBuilder withLength(int length) {
film.setLength(length);
return this;
}
public Film build() {
return film;
}
}
有沒有辦法將「setX()」更改爲「withX()」,Serge? – ae6rt 2013-07-18 19:05:04
或者你可以改變setX()爲x()嗎? – Kurru 2014-03-01 22:29:58
不錯!從來沒有新的存在。謝謝 – vikingsteve 2014-08-22 06:59:13