1

我正在尝试开始使用 Lombok。作为官方演示文档状态,应该能够通过以下简单步骤编译带有 lombok 注释的类:

  1. 创建一个类并在代码中包含@Data注释。应该是这样的

    public @Data class Test {
        private final String name;
    
        public static void main(String[] args) {
            System.out.println(new Test("name"));
        }
    }
    
  2. 使用 javac 编译并将lombok.jar放入类路径:

    javac -cp lombok.jar Test.java -verbose  
    

不幸的是,这样做我遇到了一个错误:

Round 1:
        input files: {test.Test}
        annotations: [Data]
        last round: false
Processor lombok.launch.AnnotationProcessorHider$AnnotationProcessor matches [Data] and returns false.
[parsing started lombok.javac.apt.EmptyLombokFileObject@54f47846]
[parsing completed 1ms]
[loading ZipFileIndexFileObject[C:\Program Files\Java\jdk1.8.0_144\lib\ct.sym(META-INF/sym/rt.jar/java/lang/Object.class)]]
[loading ZipFileIndexFileObject[C:\Program Files\Java\jdk1.8.0_144\lib\ct.sym(META-INF/sym/rt.jar/java/lang/String.class)]]
Round 2:
        input files: {}
        annotations: []
        last round: false
Processor lombok.launch.AnnotationProcessorHider$AnnotationProcessor matches [] and returns false.
[loading ZipFileIndexFileObject[C:\Program Files\Java\jdk1.8.0_144\lib\ct.sym(META-INF/sym/rt.jar/java/lang/Object.class)]]
[loading ZipFileIndexFileObject[C:\Program Files\Java\jdk1.8.0_144\lib\ct.sym(META-INF/sym/rt.jar/java/lang/String.class)]]
Round 3:
        input files: {}
        annotations: []
        last round: true
Test.java:3: error: cannot find symbol
public @Data class Test {
        ^
  symbol: class Data
[total 506ms]
1 error

我有javac 1.8.0_144lombok 1.18.0并在 Windows 8.1 Pro 上运行它。

任何想法都会非常有帮助!

4

1 回答 1

1

编译错误的原因是错过了导入:

import lombok.Data

感谢@SzymonStepniak 发现了这个问题。

于 2018-07-09T10:40:00.807 回答