[英]How can I force eclipse to generate my setters with a return statement
I want my eclipse to return this
in a generated setter. 我希望日食在生成的setter中返回
this
。 This would be very useful for the Builder-Pattern 这对于Builder-Pattern非常有用
What eclipse does by default: 默认情况下,eclipse会执行以下操作:
public void set{uppercase_field_name}({field_type} {field_name}) {
this.name = name;
}
What i want eclipse to do: 我想日食做什么:
public {class_type} set{uppercase_field_name}({field_type} {field_name}) {
this.name = name;
return this;
}
I found some templates that can be modified under: 我找到了一些可以在下面修改的模板:
Preferences -> Java -> Code Style -> Code Templates
But it is only possible to edit the body of the setter and not the setter signature. 但是只能编辑设置者的正文,而不能编辑设置者签名。
I found the answer very quickly after i googled some more: 在Google搜索更多内容后,我很快找到了答案:
Generate setters that return self in Eclipse 生成在Eclipse中返回self的setter
I find this approach even better, because i don't have to apply the build pattern every time i generate setters. 我发现这种方法更好,因为我不必每次生成setter时都应用构建模式。 Which by convention should always be
void
. 按照惯例,哪个应该总是
void
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.