如何在 Lombok 中自定义方法名称

huangapple go评论163阅读模式
英文:

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;

huangapple
  • 本文由 发表于 2020年8月24日 14:53:41
  • 转载请务必保留本文链接:https://go.coder-hub.com/63556052.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定