Can't create Lombok class inside my test class: modifier static not allowed here

@Builder makes a static internal class inside. The problem is probably the static internal class inside the non-static internal class.

Try to make User also static

//other annotations
@Builder    
static class User {
    String property1;
    Instant property2;
    Integer property3;
}

Defining your inner class as static will solve this.

Background: every instance on an inner class will have a reference to the object of the outer class that created it, unless the inner class ist defined as static. Usually you will not need that reference, that's why you should define your inner classes as static (this is a good static even from the PoV of OOP unlike static methods and fields).

Lombok @Builder will define a static method in your inner class (builder()), that's only allowed in static inner classes.

Tags:

Java

Lombok