英文:
How to customize a method name in lombok
问题
有谁知道如何在 lombok 中更改/自定义方法名称?
例如,我想将名称 getContributionType()
更改为 getType()
:
@Getter
@Setter
private String contributionType;
当我想获取贡献类型时,方法名称将是 getContributionType()
。但我想将它更改为:
private String contributionType;
public String getType() {
return contributionType;
}
public void setType(final String type) {
this.contributionType = type;
}
英文:
Does anyone know how to change/customize the method name in lombok?
For example, I would like to change the name getContributionType()
to getType()
:
@Getter
@Setter
private String contributionType;
When I want to get contribution type, the method name will be getContributionType()
. But I would like to change it to:
private String contributionType;
public String getType() {
return contributionType;
}
public void setType(final String type) {
this.contributionType = type;
}
答案1
得分: 1
一般情况下,您不能使用 Lombok 重命名那些方法。但是,您可以告诉它去掉前缀,这可能在您的情况下有效,尽管它并非旨在完全截断单词 :).
@Getter
@Setter
@Accessors(prefix="contribution")
private String contributionType;
英文:
In general you cannot rename those methods with Lombok. You can however tell it to strip prefixes which probably works in your case though it's not designed for chopping whole words off :).
@Getter
@Setter
@Accessors(prefix="contribution")
private String contributionType;
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论