Make a note of the technique used by seniors at work
This is a convenient library that automatically generates boilerplate code (a standard code that cannot be omitted due to language specifications) at compile time. For example, JavaBean getters / setters can be annotated.
I want to prevent instantiation with a Utility-like class that has only static methods!
Effective Java also has a memory that was described like this.
sample
public class HogeUtils {
private HogeUtils() {
// some exception
}
// some static method
}
Just annotate @NoArgsConstructor
to the class: angel:
sample
@NoArgsConstructor(access=AccessLevel.PRIVATE) // <-here
public class HogeUtils {
// some static method
}
@NoArgsConstructor
Annotation to generate the default constructor. [TERASOLUNA Server Framework for Java (5.x) Development Guideline | 11.2. Elimination of Boilerplate Code (Lombok)](http://terasolunaorg.github.io/guideline/5.3.1.RELEASE/en/Appendix/Lombok .html)
As the name suggests, the option ʻaccess = AccessLecel.PRIVATE` sets the access modifier privately. With this annotation, you'll be generating the same code you would normally do.
Lombok Wow, that's it.
Recommended Posts