package ee;
import lombok.Builder;
@Builder
public class BuilderExample {
public String foo;
public String ha;
}
package ee;
import ee.BuilderExample ;
public class Main{
public static void main(String a[]){
BuilderExample b=BuilderExample.builder().foo("hi").ha("anything").build();
}}
In this code it shows an error The method builder() is undefined for the type BuilderExample Exception in thread "main" java.lang.Error: Unresolved compilation problem: The method builder() is undefined for the type BuilderExample showing an error like this why?
The @Builder annotation produces complex builder APIs for the annotated POJO classes. For example, if we annotate a class Article annotated with @Builder annotation, we can create Article instances using builder API.
The @Builder annotation produces complex builder APIs for your classes. @Builder lets you automatically produce the code required to have your class be instantiable with code such as: Person. builder()
Follow the below steps for eclipse/STS
If it is still not resolved then close your project and open again.
Hope it works.
I faced the issue in both Intellij and eclipse Just by installing the lombok, we can simply erradicate the issue
Infact I have followed the answers in this question to solve the issue, but making it even more clear and understandable for layman also
Step 1:
Close your IDE.
Step 2:
Download lombox jar => https://projectlombok.org/download
Step 3:
Run the jar. To run the jar, Open command prompt in the jar location and enter below command
java -jar lombok.jar
After giving this command It will prompt you something like this
If your IDE is not there is in default locations, you will encounter such issues Click OK and specify the path of your IDE ex: Eclipse
After Specifying the path, the plugin will the installed
Step 4 :
Open your IDE and ReBuild your project
Now you won't face any issue.
If you are using Eclipse, make sure lombok is installed correctly. You can verify that in the Eclipse About dialog, as described at the lombok website.
For Visual Studio Code users, the solution is add the following dependency to pom.xml
:
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
<version>1.18.20</version>
<scope>provided</scope>
</dependency>
Sources:
Install lombok in your eclipse. Do the following steps
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