Java Records and Lombok annotation - IntelliJ

六眼飞鱼酱① 提交于 2020-03-23 07:26:07

问题


Just trying a hands-on the java.lang.Record. I have gone through the documentation and the JEP-359 for some understanding. So upon reading about the implicit declaration of the constructor I thought of mixing it up with an existing code generation library - Lombok!

Now what I've ended up creating as a minimal reproducible example is this record

import lombok.AllArgsConstructor;

@AllArgsConstructor
public record Java(String version) {
}

which when compiled using IntelliJ successfully produces the class file which looks like

public final class Java extends java.lang.Record {
    private final java.lang.String version;
    public Java(java.lang.String version) { /* compiled code */ }
    ... rest of the compiled code
} 

Note that the constructor for the .class file is just what I would have expected in the two worlds independently as well. But, further trying to create an instance of this record fails during compilation in IntelliJ :

public class MixOfWorlds {

    public static void main(String[] args) {
        System.out.println(new Java("14").version()); // cannot resolve constructor
    }
}

I would create a further simpler example to perform the compilation with javac and execution with java tools. I am still looking for an answer if this is a possible expected behavior that could occur because of something I might have overlooked?

IntelliJ IDEA 2020.1 EAP (Community Edition)
Build #IC-201.6487.11, built on March 18, 2020 
Runtime version: 11.0.6+8-b765.15 x86_64 
macOS 10.14.6

来源:https://stackoverflow.com/questions/60795837/java-records-and-lombok-annotation-intellij

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!