I am trying to automatize the getter and setter methods in my JavaBean.
Since, method and field naming conventions are described for Beans @ Naming Convention , there has to be a way to use this conventions in-order to avoid the boiler plate code such as writing getter and setter methods for every bean. I found one such way here .
I am using Eclipse Helios IDE with Java SE 6 in my Windows machine. Though Eclipse do provides a way to generate getter and setter methods without explicitly writing them, using annotations would make the code much more cleaner and readable.
However, when I write the following code in my Eclipse I get the following error @ Compile-time:
private @Getter @Setter int price;
Error :
Getter cannot be resolved to a type.
Setter cannot be resolved to a type.
How do I resolve it??
@Getter
and @Setter
are not part of Java. Project Lombok has annotations with these names, so you should look into how to set it up.
People who may still be not getting @Getter and @Setter recognized by eclipse you have to follow the installation instruction for lombok.jar. For eclipse you will have to
On eclipse Execute lombok.jar (doubleclick it, or run java -jar lombok.jar).
then restart eclipse only then eclipse will recognize the @Getter and @Setter. Simply having lombok.jar in build path may not solve this on eclipse.
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.16.6</version>
<scope>provided</scope>
</dependency>
I resolved by using this dependency in pom.xml.
Even though it works, you shouldn't make it a regular practice. Multiple people working on the same code may not have the same setup that you have.
We spent almost a day trying to figure out why something wouldn't compile correctly on our build server and turned out it was caused by some annotations that were auto-generated by eclipes.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.