• 请不要在回答技术问题时复制粘贴 AI 生成的内容
persona5
V2EX  ›  程序员

使用 lombok 时,两个字段(testName、testname)只生成了一组 getter/setter

  •  
  •   persona5 · Sep 16, 2020 · 4205 views
    This topic created in 2245 days ago, the information mentioned may be changed or developed.

    TestEntity.java

    @NoArgsConstructor
    @Data
    public class TestEntity {
    
        private String testName;
        private String testname;
    }
    

    TestEntity.class

    public class TestEntity {
        private String testName;
        private String testname;
    
        public TestEntity() {
        }
    
        public String getTestName() {
            return this.testName;
        }
    
        public void setTestName(final String testName) {
            this.testName = testName;
        }
    
        ...
    }
    

    请问这是什么原因?

    Supplement 1  ·  Sep 16, 2020
    1. lombok 1.18.12 ,JDK 11, IDEA 2020.2.1, 最新版本插件

    2. 不是我写的,旧项目要修改,拿出来编译的时候发现的。

    3. 能看出来八成是命名问题,但是想知道具体的原因,所以来问问。
    Supplement 2  ·  Sep 16, 2020
    https://github.com/rzwitserloot/lombok/issues/2130

    https://projectlombok.org/features/GetterSetter

    No method is generated if any method already exists with the same name (case insensitive) and same parameter count.
    21 replies  •  2020-09-16 17:59:47 +08:00
    0x663
    0x663
    Sep 16, 2020
    2
    左转 issues
    li517316684
    li517316684
    Sep 16, 2020
    3
    没导对包吧
    hejawy
    hejawy
    Sep 16, 2020
    4
    为啥要这么命名?没事找事?
    persona5
    persona5
    OP
    Sep 16, 2020
    5
    @li517316684 导包正确,不是 import 错误的问题


    @hejawy 不是我写的,旧项目要修改,拿出来编译的时候发现的
    dovme
    dovme
    Sep 16, 2020
    6
    你这么命名真的会被人打死的
    Kilerd
    Kilerd
    Sep 16, 2020
    7
    项目上用 lombok 1.18.12 没有出现这个问题,可以正常提示。 请贴出你的 lombok 版本。
    Qlccks2
    Qlccks2
    Sep 16, 2020
    8
    看来你自己知道命名有问题了
    persona5
    persona5
    OP
    Sep 16, 2020
    9
    @Kilerd lombok 版本相同,JDK 11, IDEA 2020.2.1, 最新版本插件
    hejawy
    hejawy
    Sep 16, 2020
    10
    @persona5 重构它!
    persona5
    persona5
    OP
    Sep 16, 2020
    11
    @Kilerd 是的,IDE 中可以正常提示,但是不能通过编译。
    talen666
    talen666
    Sep 16, 2020
    12
    会不会 testname 没有用到。。
    Jrue0011
    Jrue0011
    Sep 16, 2020
    13
    用 delombok 看看生成的代码
    persona5
    persona5
    OP
    Sep 16, 2020
    15
    @serical 感谢
    22k
    22k
    Sep 16, 2020
    16
    是不是驼峰名字然后认为了一个字段
    graffitist
    graffitist
    Sep 16, 2020
    17
    按道理来说,就算你命名成这个样子
    也会有两个吧?
    getTestName
    getTestname

    没注意过
    flowercoder
    flowercoder
    Sep 16, 2020
    18
    早就吃过 lombok 大小写的亏了
    getset 用插件生成一下难道不香吗?
    要么就全小写避免呗。
    Jooooooooo
    Jooooooooo
    Sep 16, 2020
    19
    (又一个不要用 lombok 的例子

    你用 idea 的自动生成 get set, 不会有问题
    shuqin2333
    shuqin2333
    Sep 16, 2020
    20
    吃过类似的亏
    aName
    生成的 get set 是 getAName 和 setAName
    手动用 idea 生成的是 getaName 和 setaName,lombok 生成的 get set 反射会有问题
    CantSee
    CantSee
    Sep 16, 2020
    21
    1.18.0 复现
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   2258 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 44ms · UTC 00:19 · PVG 08:19 · LAX 16:19 · JFK 19:19
    ♥ Do have faith in what you're doing.