Project Lombok

Project Lombok is a java library that automatically plugs into your editor and build tools, spicing up your java.
Never write another getter or equals method again, with one annotation your class has a fully featured builder, Automate your logging variables, and much more.

Project Lombok webpage: https://projectlombok.org/

How Lombok Works

  • Hooks in via the Annotation processor API
  • The AST (raw source code) is passed to Lombok for code generation before java continues.
  • Thus, produces properly compiled Java code in conjunction with the Java compiler

Project Lombok and IDEs

  • Since compiled code is changed, and source files are not, IDE’s can get confused by this.
  • Modern IDEs such as IntelliJ, Eclipse, Netbeans support Project Lombok
  • Plugin Installation may be necessary

Project Lombok Features

  • @Getter – Creates getter methods for all properties
  • @Setter – Creates setter for all non-final properties
  • @ToString – Generates String of classname, and each field separated by commas; Optional parameter to include field names; Optional parameter to include the call to the super toString method
  • @EqualsAndHashCode – Generates implementations of ‘equals(Object other) and hashCode(); By default will use all non-static, non-transient properties; Can optionally exclude specific properties.
  • @NoArgsConstructor – Generates no-args constructor; Will cause compiler error if there are final fields; Can optionally force, which will initialize final fields with 0 / false / null
  • @RequiredArgsContructor – Generates a constructor for all fields that are final or marked @NonNull; Constructor will throw a NullPointerException if any @NonNull fields are null.
  • @Data – Generates typical boilerplate code for POJOs, Combines – @Getter, @Setter, @ToString, @EqualsAndHashCode, @RequiredArgsConstructor; No constructor is generated if constructors have been explicitly declared.
  • @Value – The immutable variant of @Data; All fields are made private and final by default.
  • @NotNull – Set on a parameter of method or constructor and a NullPointerException will be thrown if the parameter is null.
  • @Builder – Implements the ‘builder’ pattern for object creation.
  • @SneakyThrows – Throw checked exceptions without declaring in calling method’s throws clause.
  • @Syncronized – A safer implementation of Java’s synchronized
  • @Log – Creates a Java util logger.
  • @Slf4j – Creates a SLF4J logger.

Difference between HashMap and HashSet in Java


Fatal error: Uncaught Error: Call to a member function id() on array in /home/progra49/public_html/wp-content/plugins/crayon-syntax-highlighter/crayon_formatter.class.php:36 Stack trace: #0 /home/progra49/public_html/wp-content/plugins/crayon-syntax-highlighter/crayon_formatter.class.php(538): CrayonFormatter::format_code('', Array, Object(CrayonHighlighter)) #1 [internal function]: CrayonFormatter::delim_to_internal(Array) #2 /home/progra49/public_html/wp-content/plugins/crayon-syntax-highlighter/crayon_formatter.class.php(516): preg_replace_callback('#()#msi', 'CrayonFormatter...', 'import java.uti...') #3 /home/progra49/public_html/wp-content/plugins/crayon-syntax-highlighter/crayon_highlighter.class.php(166): CrayonFormatter::format_mixed_code('import java.uti...', Object(CrayonLang), Object(CrayonHighlighter)) #4 /home/progra49/public_html/wp-content/plugins/crayon-syntax-highlighter/crayon_highlighter.class.php(186): CrayonHighlighter->process() #5 /home/progra49/public_html/wp-content/plugins/crayon-syntax-highligh in /home/progra49/public_html/wp-content/plugins/crayon-syntax-highlighter/crayon_formatter.class.php on line 36