lombok知识点

引用:The getters generated correctly follow convention for boolean properties, resulting in an isFoo getter method name instead of getFoo for any boolean field foo. It should be noted that if the class to which the annotated field belongs contains a method of the same name as the getter or setter to be generated, regardless of parameter or return types, no corresponding method will be generated ,

翻译:对于布尔类型的属性生成getter方法遵循约定: boolen foo; 生成getter方法为isFoo(),而不是getFoo(),需要注意的是,如果类中某个字段加了@Getter或@Setter注解,并且该字段还存在相应的自定义的getter或setter方法,那么无论getter或setter方法的参数或返回类型是什么样的,@Getter或@Setter注解将不生效。

代码:
package com.springboot.demo;

import lombok.Getter;
import lombok.Setter;

/**
 * @author xxl
 * @date 2020/05/12
 */
@Getter
@Setter
public class Programmer {

    private Integer age;

    private String name;

    private Boolean hasCar;

    private String hairline;

    public Integer getAge() {
        System.out.println("使用自定义的getter");
        return age;
    }

    public static void main(String[] args) {
        Programmer programmer = new Programmer();
        programmer.setAge(28);
        System.out.println(programmer.getAge());
    }
}

---------------------------------------------------------
输出:
使用自定义的getter
28

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章