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

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

  •  
  •   persona5 · Sep 16, 2020 · 3709 views
    This topic created in 2078 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
        2
    0x663  
       Sep 16, 2020
    左转 issues
    li517316684
        3
    li517316684  
       Sep 16, 2020
    没导对包吧
    hejawy
        4
    hejawy  
       Sep 16, 2020
    为啥要这么命名?没事找事?
    persona5
        5
    persona5  
    OP
       Sep 16, 2020
    @li517316684 导包正确,不是 import 错误的问题


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

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

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