简体   繁体   中英

how to create like lombok annotation @getter?

I want to create an annotation(=@MyGetter) that does this

@MyGetter
public class AnyClass {

    private String fieldVariable;

}

convert to (on compile)

@MyGetter
public class AnyClass {

    private String fieldVariable;

    public String getFieldVariable() {
        if (isHexString()) {
            return ... // process
        }
        return fieldVariable
    }
}

In short, I want to create a getter that returns a string according to a specific condition when I put the annotation I made.

how can create this?

Try to use JavaAnnotationProcessor to parse the custom annotation and generate the target code while compiling.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM