Before starting, when looking for an answer to this question I've looked at the following question which didn't answer mine: * Is it possible to add @Builder and @AllArgsConstructor in static inner classes [Lombok]?
In my tests, I created an inner class that holds my test cases:
@AllArgsConstructor
@Getter
static class TestData {
private final String testCase;
private final String value1;
private final String value2;
private final int value3;
}
Also in those tests, I have a list containing all of those test cases:
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),
));
However, when I'm compiling the code I'm getting the following error:
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
EDIT Since it seems to be something that does not work on my project I'm attaching my complete example code that is failing:
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;
}
}
This is my build.gradle file:
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'
}
EDIT2 You can find the code example in the project that I'm running on my machine (and some of my colleges) in this GitHub repo: https://github.com/yonatankarp/stackoverflow_lombok
I don't know what's wrong with your setup, but I could reproduce and solve your problem.
Note that you problem has nothing to do with nested(*) classes, Lombok AFAIK didn't run at all.
This is my 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'
}
I removed all mentions of lombok and added and configured a plugin doing this right.
I have no clue what was wrong.
(*) TestData is "nested", but not "inner". No idea, why, but that's what Oracle says: https://docs.oracle.com/javase/tutorial/java/javaOO/nested.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With