Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
407 views
in Technique[技术] by (71.8m points)

java - Lombok how to customise getter for Boolean object field?


One of my POJOs has a Boolean object field to permit NULLS in the database (a requirement). Is it possible to use the @Data Lombok annotation at class level yet override the getter for the Boolean field? The default it generates is getXXX method for the Boolean field. I wish to override it as isXXX()?

Thanks,
Paddy

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

It's a bit verbose, but you can provide your own isXXX, and then use AccessLevel.NONE to tell Lombok not to generate the getXXX:

@Data
public class OneOfPaddysPojos {

    // ... other fields ...

    @Getter(AccessLevel.NONE)
    private Boolean XXX;

    public Boolean isXXX() {
        return XXX;
    }
}

(And hey, at least it's not quite as verbose as if you weren't using Lombok to begin with!)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...