- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
在开始之前,在寻找这个问题的答案时,我查看了以下问题,但它没有回答我的问题:* Is it possible to add @Builder and @AllArgsConstructor in static inner classes [Lombok]?
在我的测试中,我创建了一个内部类来保存我的测试用例:
@AllArgsConstructor
@Getter
static class TestData {
private final String testCase;
private final String value1;
private final String value2;
private final int value3;
}
此外,在这些测试中,我有一个包含所有这些测试用例的列表:
private static final List<TestData> testData = Collections.unmodifiableList(Arrays.asList(
new TestData("test case 1", "value1", "value2", 1),
new TestData("test case 2", "value2", "value2", 2),
new TestData("test case 3", "value2", "value1", 3),
new TestData("test case 4", "value2", "value2", 4),
));
但是,当我编译代码时,出现以下错误:
error: constructor TestData in class TestData cannot be applied to given types;
new TestData("test case 1", "value1", "value2", 1),
^
required: no arguments
found: String,String,String,int
reason: actual and formal argument lists differ in length
编辑由于它似乎不适用于我的项目,因此我附上了失败的完整示例代码:
public class Testing {
private static final List<TestData> testData = Collections.unmodifiableList(Arrays.asList(
new TestData("test case 1", "value1", "value2", 1),
new TestData("test case 2", "value2", "value2", 2),
new TestData("test case 3", "value2", "value1", 3),
new TestData("test case 4", "value2", "value2", 4)
));
@Test
public void aTest() {
for (final TestData data : testData) {
System.out.println("***********************");
System.out.println(data.getTestCase());
System.out.println(data.getValue1());
System.out.println(data.getValue2());
System.out.println(data.getValue3());
}
}
@AllArgsConstructor
@Getter
static class TestData {
private final String testCase;
private final String value1;
private final String value2;
private final int value3;
}
}
这是我的 build.gradle 文件:
plugins {
id 'java'
}
group 'org.example'
version '1.0-SNAPSHOT'
sourceCompatibility = 1.8
repositories {
mavenCentral()
}
dependencies {
compileOnly 'org.projectlombok:lombok:1.18.10'
annotationProcessor 'org.projectlombok:lombok:1.18.10'
testCompile 'junit:junit:4.12'
testCompile 'org.projectlombok:lombok:1.18.10'
}
编辑2您可以在此 GitHub 存储库中找到我在我的计算机(以及我的一些大学)上运行的项目中的代码示例: https://github.com/yonatankarp/stackoverflow_lombok
最佳答案
我不知道您的设置有什么问题,但我可以重现并解决您的问题。
请注意,您的问题与嵌套(*)类无关,Lombok AFAIK 根本没有运行。
这是我的build.gradle
:
plugins {
id 'java'
id "io.freefair.lombok" version "4.0.1"
}
lombok {
version = "1.18.10"
}
group 'org.example'
version '1.0-SNAPSHOT'
sourceCompatibility = 1.8
repositories {
mavenCentral()
}
dependencies {
testCompile 'junit:junit:4.12'
}
我删除了所有提及 lombok
的内容,并添加并配置了一个插件来正确执行此操作。
我不知道出了什么问题。
<小时/>(*) TestData
是“嵌套的”,但不是“内部的”。不知道为什么,但这就是 Oracle 所说的:https://docs.oracle.com/javase/tutorial/java/javaOO/nested.html
关于java - 内部静态类的 Lombok 注释,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59749820/
我正在尝试扩展 Lombok通过创建我自己的注释。 我设法拥有 LombokizedEclipse.launch由 ant 创建,我写了 before和 after文件。 ant test我的注释失败
我在我的项目中广泛使用了 Lombok。我喜欢它,并希望它能得到官方支持,这样维护者就不必使用内部 API 来继续开发,但这是另一个话题了。 在使用 val 时,我经常会在编译过程中遇到以下问题: (
我发现使用 lombok @toString 和跳过空字段行为的简单方法没有成功。 我认为使用方面编程为所有函数创建我自己的 toString 函数。像那样,我可以检查所有空字段并跳过它。 但这是一种
有没有一种方法可以用lombok定义“PostConstruct”初始化方法? @RequiredArgsConstructor(staticName = "of") class MyObj {
Lombok 是一个很棒的插件,它有一个 Eclipse 和 IntelliJ 的安装程序。 AnyLogic 是基于 Eclipse 的,那么我们如何让它也在那里工作呢? 最佳答案 在 Mac 上,
我在我的项目中使用过Lombok,但是我的同事不同意使用它,他的理由是(来自controversy of lombok documents ) Both of these pieces of Proj
我一直在尝试向 Lombok 添加自定义注释。我的起点是 GitHub 上的源代码分支。 我添加了一个工作正常的注释。我可以使用包含的 eclipse 启动(或构建一个 jar 并将其交换到我的 ec
我用 Intellij 打开了 restbucks 项目。我安装了 lombok 插件,启用了注释处理。我在 Intellij 设置中使用 javac 编译器。我在项目根目录中有 lombok.con
我正在尝试利用 Lombok 的新 copyableAnnotations 功能,以便将 @JsonIgnore 和 @JsonValue 等 Jackson 注释复制到生成的 getter/with
我正在尝试在一个项目中使用 lombok,在这个项目中我有一个抽象基模型类,而其他类是从它派生的。但是我在编译时遇到错误。代码如下所示: 基础实体.java import java.util.Date
升级后,无法从 Intellij IDE 运行应用程序。 Intellij 版本:IntelliJ IDEA 2020.3(社区版) Build #IC-203.5981.155,建于 2020 年
我正在使用具有以下结构的 IntelliJ IDEA 2016.3 + lombok 插件: 编辑:这是模块内容根配置: 在 src/main/java 和 src/test/java 中一切都按预期
我在我的根目录中创建了一个 lombok.config 文件,内容如下: config.stopBubbling = true lombok.addLombokGeneratedAnnotation
我在我的 gradle 项目中使用 lombok 并想要创建一个 jar 文件,但每次执行 jar 任务(无论是否在我的控制台或 eclipse ide 中触发)我都会收到错误,在这些类中找不到我的
我需要为基于 JNI 的 native 库编译 .h 文件。在我的项目中添加一些 lombok 注释后,我无法使用 javac 编译 .h 文件。我正在使用 IntelliJ 和等级。我正在尝试在 i
@Data public abstract class B { private final String str; } @Data public class A extends B{ pr
@Builder public class ProcessorLombokBO { private String panel; private String motherBoard;
最近,我对“lombok”产生了很大的兴趣。我想通过阅读源代码来更多地了解它。 但是尝试之后,我发现这对我来说真的很难。我只发现有“javac”和“ECJ”两个实现。但不明白它是如何端到端工作的。 有
我有一个看起来像这样的类: @EqualsAndHashCode @RequiredArgsConstructor public class StatusUpdate { @Getter
这个问题在这里已经有了答案: Lombok getter/setter vs Java 14 record (6 个回答) 去年关闭。 记录是自 Java 14(第一次预览版)和 Java 15(第二
我是一名优秀的程序员,十分优秀!