-
Notifications
You must be signed in to change notification settings - Fork 0
/
project-lombok.html
18 lines (17 loc) · 16 KB
/
project-lombok.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
<!DOCTYPE html><html lang="de-ch"><head><meta charset="utf-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width,initial-scale=1"><title>Project Lombok - Finecloud</title><meta name="description" content="Intro Project Lombok is a Java library that provides a set of annotations and utility classes that help to reduce boilerplate code in Java projects. It offers features such as automatic generation of getters, setters, equals, hashCode, toString, and constructors, as well as support for…"><meta name="generator" content="Publii Open-Source CMS for Static Site"><link rel="stylesheet" href="https://www.finecloud.ch/media/plugins/syntaxHighlighter/prism-black.css"><link rel="canonical" href="https://www.finecloud.ch/project-lombok.html"><link rel="alternate" type="application/atom+xml" href="https://www.finecloud.ch/feed.xml"><link rel="alternate" type="application/json" href="https://www.finecloud.ch/feed.json"><meta property="og:title" content="Project Lombok"><meta property="og:site_name" content="Finecloud"><meta property="og:description" content="Intro Project Lombok is a Java library that provides a set of annotations and utility classes that help to reduce boilerplate code in Java projects. It offers features such as automatic generation of getters, setters, equals, hashCode, toString, and constructors, as well as support for…"><meta property="og:url" content="https://www.finecloud.ch/project-lombok.html"><meta property="og:type" content="article"><link rel="shortcut icon" href="https://www.finecloud.ch/media/website/finecloud.png" type="image/png"><link rel="stylesheet" href="https://www.finecloud.ch/assets/css/style.css?v=39da73365516a098a9b73b721fc970e2"><script type="application/ld+json">{"@context":"http://schema.org","@type":"Article","mainEntityOfPage":{"@type":"WebPage","@id":"https://www.finecloud.ch/project-lombok.html"},"headline":"Project Lombok","datePublished":"2023-04-05T21:00","dateModified":"2023-04-04T21:00","description":"Intro Project Lombok is a Java library that provides a set of annotations and utility classes that help to reduce boilerplate code in Java projects. It offers features such as automatic generation of getters, setters, equals, hashCode, toString, and constructors, as well as support for…","author":{"@type":"Person","name":"Finecloud","url":"https://www.finecloud.ch/authors/finecloud/"},"publisher":{"@type":"Organization","name":"Finecloud"}}</script><meta name="google-site-verification" content="seFY9U12uiEq5U3_MyZiX6XWzk0AVFl9zITr2ZKsytY"></head><body><div class="site-container"><header class="top" id="js-header"><a class="logo" href="https://www.finecloud.ch/">Finecloud</a><nav class="navbar js-navbar"><button class="navbar__toggle js-toggle" aria-label="Menu" aria-haspopup="true" aria-expanded="false"><span class="navbar__toggle-box"><span class="navbar__toggle-inner">Menu</span></span></button><ul class="navbar__menu"><li><a href="https://www.finecloud.ch/" target="_self">Blog</a></li><li><a href="https://www.finecloud.ch/tags/" target="_self">Tags</a></li></ul></nav><div class="search"><div class="search__overlay js-search-overlay"><div class="search__overlay-inner"><form action="https://www.finecloud.ch/search.html" class="search__form"><input class="search__input js-search-input" type="search" name="q" placeholder="search..." aria-label="search..." autofocus="autofocus"></form><button class="search__close js-search-close" aria-label="Close">Close</button></div></div><button class="search__btn js-search-btn" aria-label="Search"><svg role="presentation" focusable="false"><use xlink:href="https://www.finecloud.ch/assets/svg/svg-map.svg#search"/></svg></button></div></header><main><article class="post"><div class="hero"><figure class="hero__image hero__image--overlay"><img src="https://www.finecloud.ch/media/website/download.jpg" srcset="https://www.finecloud.ch/media/website/responsive/download-xs.jpg 300w, https://www.finecloud.ch/media/website/responsive/download-sm.jpg 480w, https://www.finecloud.ch/media/website/responsive/download-md.jpg 768w, https://www.finecloud.ch/media/website/responsive/download-lg.jpg 1024w, https://www.finecloud.ch/media/website/responsive/download-xl.jpg 1360w, https://www.finecloud.ch/media/website/responsive/download-2xl.jpg 1600w" sizes="100vw" loading="eager" alt=""></figure><header class="hero__content"><div class="wrapper"><div class="post__meta"><time datetime="2023-04-05T21:00">April 5, 2023</time></div><h1>Project Lombok</h1></div></header></div><div class="wrapper post__entry"><div class="post__toc"><h3>Table of Contents</h3><ul><li><a href="#mcetoc_1gt6q7uargb">Intro</a></li><li><a href="#mcetoc_1gt6q7uargc">How does it work?</a></li><li><a href="#mcetoc_1gt6q7uargd">Features</a></li></ul></div><h3 id="mcetoc_1gt6q7uargb">Intro</h3><div class="flex flex-grow flex-col gap-3"><div class="min-h-[20px] flex flex-col items-start gap-4 whitespace-pre-wrap"><div class="markdown prose w-full break-words dark:prose-invert light"><p>Project Lombok is a Java library that provides a set of annotations and utility classes that help to reduce boilerplate code in Java projects. It offers features such as automatic generation of getters, setters, equals, hashCode, toString, and constructors, as well as support for logging, fluent API creation, and more.</p><p>By using Lombok annotations, developers can focus on writing the core business logic of their code and let Lombok generate the repetitive, boilerplate code for them. This reduces code verbosity and can lead to improved code readability and maintainability.</p><p>Lombok is widely used in the Java community and can be integrated into popular IDEs such as Eclipse, IntelliJ, and NetBeans. It is also compatible with popular build tools such as Maven and Gradle.</p><p>Overall, Lombok is a powerful tool for Java developers who want to increase productivity and reduce the amount of repetitive code in their projects.</p><h3 id="mcetoc_1gt6q7uargc">How does it work?</h3><div class="page" title="Page 4"><div class="section"><div class="layoutArea"><div class="column"><ul><li><p>Hooks in via the Annotation processor API</p></li><li>The AST (raw source code) is passed to Lombok for code generation before java continues.</li><li>Thus, produces properly compiled Java code in conjunction with the Java compiler</li><li>NOTE: Code is generated and complied. No run-time performance penalty.</li><li><span style="color: var(--text-primary-color); font-family: var(--editor-font-family); font-size: inherit; font-weight: var(--font-weight-normal);">If you write an implantation of a method Project Lombok would generate, your code is used</span></li><li><span style="color: var(--text-primary-color); font-family: var(--editor-font-family); font-size: inherit; font-weight: var(--font-weight-normal);">Make it easy to override Lombok generated code</span></li></ul><h3 id="mcetoc_1gt6q7uargd">Features</h3><ul><li>val - declares final local variable</li><li>var - declares mutable local variable</li><li>@Getter<ul><li>Creates getter methods for all properties</li></ul></li><li>@Setter<ul><li>Creates setter for all non-final properties</li></ul></li><li>@ToString<ul><li>Generates String of classname, and each field separated by commas</li><li>Optional parameter to include field names</li><li>Optional parameter to include call to the super toString method</li></ul></li><li><span style="color: var(--text-primary-color); font-family: var(--editor-font-family); font-size: inherit; font-weight: var(--font-weight-normal);">@EqualsAndHashCode</span><br><ul><li><span style="color: var(--text-primary-color); font-family: var(--editor-font-family); font-size: inherit; font-weight: var(--font-weight-normal);">Generates implementations of ‘equals(Object other) and hashCode()</span></li><li><span style="color: var(--text-primary-color); font-family: var(--editor-font-family); font-size: inherit; font-weight: var(--font-weight-normal);">By default will use all non-static, non-transient properties</span></li><li>Can optionally exclude specific properties</li></ul></li><li><span style="color: var(--text-primary-color); font-family: var(--editor-font-family); font-size: inherit; font-weight: var(--font-weight-normal);">@NoArgsConstructor</span><br><ul><li><span style="color: var(--text-primary-color); font-family: var(--editor-font-family); font-size: inherit; font-weight: var(--font-weight-normal);">Generates no args constructor</span></li><li><span style="color: var(--text-primary-color); font-family: var(--editor-font-family); font-size: inherit; font-weight: var(--font-weight-normal);">Will cause compiler error if there are final fields</span></li><li><span style="color: var(--text-primary-color); font-family: var(--editor-font-family); font-size: inherit; font-weight: var(--font-weight-normal);">Can optionally force, which will initialize final fields with 0 / false / null</span></li></ul></li><li><span style="color: var(--text-primary-color); font-family: var(--editor-font-family); font-size: inherit; font-weight: var(--font-weight-normal);">@RequiredArgsContructor</span><br><ul><li><span style="color: var(--text-primary-color); font-family: var(--editor-font-family); font-size: inherit; font-weight: var(--font-weight-normal);">Generates a constructor for all fields that are final or marked @NonNull</span></li><li><span style="color: var(--text-primary-color); font-family: var(--editor-font-family); font-size: inherit; font-weight: var(--font-weight-normal);">Constructor will throw a NullPointerException if any @NonNull fields are null</span></li></ul></li><li>@Data<ul><li><span style="color: var(--text-primary-color); font-family: var(--editor-font-family); font-size: inherit; font-weight: var(--font-weight-normal);">Generates typical boilerplate code for POJOs</span></li><li><span style="color: var(--text-primary-color); font-family: var(--editor-font-family); font-size: inherit; font-weight: var(--font-weight-normal);">Combines - @Getter, @Setter, @ToString, @EqualsAndHashCode, @RequiredArgsConstructor</span></li><li><span style="color: var(--text-primary-color); font-family: var(--editor-font-family); font-size: inherit; font-weight: var(--font-weight-normal);">No constructor is generated if constructors have been explicitly declared</span></li></ul></li><li><span style="color: var(--text-primary-color); font-family: var(--editor-font-family); font-size: inherit; font-weight: var(--font-weight-normal);">@Value</span><br><ul><li><span style="color: var(--text-primary-color); font-family: var(--editor-font-family); font-size: inherit; font-weight: var(--font-weight-normal);">The immutable variant of @Data</span></li><li><span style="color: var(--text-primary-color); font-family: var(--editor-font-family); font-size: inherit; font-weight: var(--font-weight-normal);">All fields are made private and final by default</span></li></ul></li><li><span style="color: var(--text-primary-color); font-family: var(--editor-font-family); font-size: inherit; font-weight: var(--font-weight-normal);">@NonNull</span><br><ul><li><span style="color: var(--text-primary-color); font-family: var(--editor-font-family); font-size: inherit; font-weight: var(--font-weight-normal);">Set on parameter of method or constructor and a NullPointerException will be thrown if parameter is null</span></li></ul></li><li><span style="color: var(--text-primary-color); font-family: var(--editor-font-family); font-size: inherit; font-weight: var(--font-weight-normal);">@Builder</span><br><ul><li><span style="color: var(--text-primary-color); font-family: var(--editor-font-family); font-size: inherit; font-weight: var(--font-weight-normal);">Implements the ‘builder’ pattern for object creation</span></li><li><span style="color: var(--text-primary-color); font-family: var(--editor-font-family); font-size: inherit; font-weight: var(--font-weight-normal);">Person.builder().name("Adam Savage").city("San Francisco").job("Mythbusters").job("Unchained Reaction").build();</span></li></ul></li><li><span style="color: var(--text-primary-color); font-family: var(--editor-font-family); font-size: inherit; font-weight: var(--font-weight-normal);">@SneakyThrows</span><br><ul><li><span style="color: var(--text-primary-color); font-family: var(--editor-font-family); font-size: inherit; font-weight: var(--font-weight-normal);">Throw checked exceptions without declaring in calling method’s throws clause</span></li></ul></li><li><span style="color: var(--text-primary-color); font-family: var(--editor-font-family); font-size: inherit; font-weight: var(--font-weight-normal);">@Syncronized</span><br><ul><li><span style="color: var(--text-primary-color); font-family: var(--editor-font-family); font-size: inherit; font-weight: var(--font-weight-normal);">A safer implementation of Java’s synchronized</span></li></ul></li><li><span style="color: var(--text-primary-color); font-family: var(--editor-font-family); font-size: inherit; font-weight: var(--font-weight-normal);">@Log</span><br><ul><li><span style="color: var(--text-primary-color); font-family: var(--editor-font-family); font-size: inherit; font-weight: var(--font-weight-normal);">Creates a Java util logger • Java util loggers are awful</span></li></ul></li><li><span style="color: var(--text-primary-color); font-family: var(--editor-font-family); font-size: inherit; font-weight: var(--font-weight-normal);">@Slf4j</span><br><ul><li><span style="color: var(--text-primary-color); font-family: var(--editor-font-family); font-size: inherit; font-weight: var(--font-weight-normal);">Creates a SLF4J logger.</span></li><li>Recommended - SLF4J is a generic logging facade</li><li>Spring Boot’s default logger is LogBack</li></ul></li></ul></div><div class="column"> </div></div></div></div></div></div></div></div><footer class="wrapper post__footer"><p class="post__last-updated">This article was updated on April 4, 2023</p><ul class="post__tag"><li><a href="https://www.finecloud.ch/tags/java/">java</a></li><li><a href="https://www.finecloud.ch/tags/softwareentwicklung/">software development</a></li><li><a href="https://www.finecloud.ch/tags/spring/">spring</a></li><li><a href="https://www.finecloud.ch/tags/spring-framework/">spring-framework</a></li></ul><div class="post__share"></div></footer></article><nav class="post__nav"><div class="post__nav-inner"><div class="post__nav-prev"><svg width="1.041em" height="0.416em" aria-hidden="true"><use xlink:href="https://www.finecloud.ch/assets/svg/svg-map.svg#arrow-prev"/></svg> <a href="https://www.finecloud.ch/spring-bean-lifecycle.html" class="post__nav-link" rel="prev"><span>Previous</span> Spring Bean Lifecycle</a></div><div class="post__nav-next"><a href="https://www.finecloud.ch/mockmvc.html" class="post__nav-link" rel="next"><span>Next</span> Testing with MockMVC </a><svg width="1.041em" height="0.416em" aria-hidden="true"><use xlink:href="https://www.finecloud.ch/assets/svg/svg-map.svg#arrow-next"/></svg></div></div></nav></main><footer class="footer"><div class="footer__copyright"><p>Powered by Publii</p></div><button onclick="backToTopFunction()" id="backToTop" class="footer__bttop" aria-label="Back to top" title="Back to top"><svg><use xlink:href="https://www.finecloud.ch/assets/svg/svg-map.svg#toparrow"/></svg></button></footer></div><script>window.publiiThemeMenuConfig = {
mobileMenuMode: 'sidebar',
animationSpeed: 300,
submenuWidth: 'auto',
doubleClickTime: 500,
mobileMenuExpandableSubmenus: true,
relatedContainerForOverlayMenuSelector: '.top',
};</script><script defer="defer" src="https://www.finecloud.ch/assets/js/scripts.min.js?v=6ca8b60e6534a3888de1205e82df8528"></script><script>var images = document.querySelectorAll('img[loading]');
for (var i = 0; i < images.length; i++) {
if (images[i].complete) {
images[i].classList.add('is-loaded');
} else {
images[i].addEventListener('load', function () {
this.classList.add('is-loaded');
}, false);
}
}</script><script defer="defer" src="https://www.finecloud.ch/media/plugins/syntaxHighlighter/prism.js"></script></body></html>