SlideShare una empresa de Scribd logo
1 de 53
Project Lombok in Java
Krzysztof Czajkowski
krzysztof.czajkowski@softwarehut.com
public class Superhero {
private String firstName;
private String lastName;
private String name;
private String superpower;
private LocalDateTime birthDate;
private List<Superhero> friends;
private List<Superhero> enemies;
}
public class Superhero {
private String firstName;
private String lastName;
private String name;
private String superpower;
private LocalDateTime birthDate;
private List<Superhero> friends;
private List<Superhero> enemies;
public Superhero() {
}
}
public class Superhero {
private String firstName;
private String lastName;
private String name;
private String superpower;
private LocalDateTime birthDate;
private List<Superhero> friends;
private List<Superhero> enemies;
private City birthPlace;
private Planet homePlanet;
private City residenceCity;
private Nature nature;
}
Can we do it easier?
public class Superhero {
private String firstName;
private String lastName;
private String name;
private String superpower;
private LocalDateTime birthDate;
private List<Superhero> friends;
private List<Superhero> enemies;
}
@Data
public class Superhero {
private String firstName;
private String lastName;
private String name;
private String superpower;
private LocalDateTime birthDate;
private List<Superhero> friends;
private List<Superhero> enemies;
}
@Data
public class Superhero {
private String firstName;
private String lastName;
private String name;
private String superpower;
private LocalDateTime birthDate;
private List<Superhero> friends;
private List<Superhero> enemies;
private City birthPlace;
private Planet homePlanet;
private City residenceCity;
private Nature nature;
}
How to add Lombok to your project?
Maven
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.16.6</version>
</dependency>
Gradle
Version < 2.12
dependencies {
provided "org.projectlombok:lombok:1.16.16"
}
Version >= 2.12
dependencies {
compileOnly "org.projectlombok:lombok:1.16.16"
}
Annotation processing
lombok.core.AnnotationProcessor extends AbstractProcessor
Getter and Setter
Getter and Setter
@Getter
@Setter
public class Superhero {
private String firstName;
private String lastName;
private String name;
private String superpower;
}
Getter and Setter
@Getter
public class Superhero {
@Setter
private String firstName;
@Setter
private String lastName;
@Setter
private String name;
private String superpower;
}
NonNull
NonNull
@Getter
@Setter
public class Superhero {
private String firstName;
private String lastName;
private String name;
@NonNull
private String superpower;
}
NonNull
public void setSuperpower(@NonNull String superpower) {
if(superpower == null) {
throw new NullPointerException("superpower");
} else {
this.superpower = superpower;
}
}
EqualsAndHashCode
@EqualsAndHashCode
public class Superhero {
private String firstName;
private String lastName;
private String name;
private String superpower;
}
EqualsAndHashCode
@EqualsAndHashCode(of = {"name"})
public class Superhero {
private String firstName;
private String lastName;
private String name;
private String superpower;
}
EqualsAndHashCode
public int hashCode() {
boolean PRIME = true;
byte result = 1;
String $name = this.name;
int result1 = result * 59 + ($name ==
null?43:$name.hashCode());
return result1;
}
EqualsAndHashCode
@EqualsAndHashCode(exclude = {„superpower"})
public class Superhero {
private String firstName;
private String lastName;
private String name;
private String superpower;
}
EqualsAndHashCodepublic int hashCode() {
boolean PRIME = true;
byte result = 1;
String $firstName = this.firstName;
int result1 = result * 59 + ($firstName ==
null?43:$firstName.hashCode());
String $lastName = this.lastName;
result1 = result1 * 59 + ($lastName ==
null?43:$lastName.hashCode());
String $name = this.name;
result1 = result1 * 59 + ($name ==
null?43:$name.hashCode());
return result1;
ToString
@ToString(of = {"name", "superpower"})
public class Superhero {
private String firstName;
private String lastName;
private String name;
private String superpower;
}
ToString
public String toString() {
return "Superhero(name=" + this.name +
", superpower=" + this.superpower + ")";
}
Generate constructors
NoArgsConstructor
NoArgsConstructor
@NoArgsConstructor
public class Superhero {
private String firstName;
private String lastName;
private String name;
private String superpower;
}
AllArgsConstructor
AllArgsConstructor
@AllArgsConstructor
public class Superhero {
private String firstName;
private String lastName;
private String name;
private String superpower;
}
AllArgsConstructor
@ConstructorProperties({"firstName", "lastName",
"name", "superpower"})
public Superhero(String firstName, String lastName,
String name, String superpower) {
this.firstName = firstName;
this.lastName = lastName;
this.name = name;
this.superpower = superpower;
}
RequiredArgsConstructor
RequiredArgsConstructor
@RequiredArgsConstructor
public class Superhero {
private final int counter;
@NonNull
private String firstName;
private String lastName;
private String name;
private String superpower;
}
RequiredArgsConstructor
@ConstructorProperties({"counter", "firstName"})
public Superhero(int counter, @NonNull String
firstName) {
if(firstName == null) {
throw new NullPointerException("firstName");
} else {
this.counter = counter;
this.firstName = firstName;
}
}
Data
@Data
public class Superhero {
private String firstName;
private String lastName;
private String name;
private String superpower;
}
Combined annotations
@RequiredArgsConstructor @ToString
@Getter
public class Superhero {
@Setter
private String firstName;
@Setter
private String lastName;
@NonNull @Setter
private String name;
private String superpower;
}
Log
@Log
public class Superhero {
public void doSomething() {
log.log(Level.INFO, "Doing something");
}
}
Log
public class Superhero {
private static final Logger log =
Logger.getLogger(Superhero.class.getName());
public Superhero() {
}
public void doSomething() {
log.log(Level.INFO, "Doing something");
}
}
Log
maj 31, 2017 8:55:24 AM com.sh.lombok.superhero.model.Superhero
doSomething
INFO: Doing something
Builder
@Builder
@ToString
public class Superhero {
private String firstName;
private String lastName;
private String name;
private String superpower;
}
Builder
public static void main(String[] args) {
Superhero batman = Superhero.builder()
.firstName("Bruce")
.lastName("Wayne")
.name("Batman")
.superpower("")
.build();
log.log(Level.INFO, batman.toString());
}
Builder
INFO: Superhero(firstName=Bruce, lastName=Wayne, name=Batman,
superpower=)
Delombok
<plugin>
<groupId>org.projectlombok</groupId>
<artifactId>lombok-maven-plugin</artifactId>
<version>1.16.16.0</version>
<executions>
<execution>
<phase>generate-sources</phase>
<goals>
<goal>delombok</goal>
</goals>
</execution>
</executions>
</plugin>
Delombok
@java.lang.SuppressWarnings("all")
@javax.annotation.Generated("lombok")
public Nature getNature() {
return this.nature;
}
@java.lang.SuppressWarnings("all")
@javax.annotation.Generated("lombok")
public void setFirstName(final String firstName) {
this.firstName = firstName;
}
Pros
•Less code
•More readable classes
•Faster development
Cons?
•Can’t detect constructor of superclass
•Using non-public API - upgrading
compiler may break your code
Project Lombok
• https://projectlombok.org/
The End

Más contenido relacionado

La actualidad más candente

From mysql to MongoDB(MongoDB2011北京交流会)
From mysql to MongoDB(MongoDB2011北京交流会)From mysql to MongoDB(MongoDB2011北京交流会)
From mysql to MongoDB(MongoDB2011北京交流会)
Night Sailer
 
OO Perl with Moose
OO Perl with MooseOO Perl with Moose
OO Perl with Moose
Nelo Onyiah
 
MongoDB: Replication,Sharding,MapReduce
MongoDB: Replication,Sharding,MapReduceMongoDB: Replication,Sharding,MapReduce
MongoDB: Replication,Sharding,MapReduce
Takahiro Inoue
 
Intro To Moose
Intro To MooseIntro To Moose
Intro To Moose
cPanel
 
Topological indices (t is) of the graphs to seek qsar models of proteins com...
Topological indices (t is) of the graphs  to seek qsar models of proteins com...Topological indices (t is) of the graphs  to seek qsar models of proteins com...
Topological indices (t is) of the graphs to seek qsar models of proteins com...
Jitendra Kumar Gupta
 

La actualidad más candente (19)

Text analysis using python
Text analysis using pythonText analysis using python
Text analysis using python
 
Typescript - why it's awesome
Typescript - why it's awesomeTypescript - why it's awesome
Typescript - why it's awesome
 
Andreas Roth - GraphQL erfolgreich im Backend einsetzen
Andreas Roth - GraphQL erfolgreich im Backend einsetzenAndreas Roth - GraphQL erfolgreich im Backend einsetzen
Andreas Roth - GraphQL erfolgreich im Backend einsetzen
 
Smelling your code
Smelling your codeSmelling your code
Smelling your code
 
From mysql to MongoDB(MongoDB2011北京交流会)
From mysql to MongoDB(MongoDB2011北京交流会)From mysql to MongoDB(MongoDB2011北京交流会)
From mysql to MongoDB(MongoDB2011北京交流会)
 
OO Perl with Moose
OO Perl with MooseOO Perl with Moose
OO Perl with Moose
 
Moose talk at FOSDEM 2011 (Perl devroom)
Moose talk at FOSDEM 2011 (Perl devroom)Moose talk at FOSDEM 2011 (Perl devroom)
Moose talk at FOSDEM 2011 (Perl devroom)
 
Natural Language Toolkit (NLTK), Basics
Natural Language Toolkit (NLTK), Basics Natural Language Toolkit (NLTK), Basics
Natural Language Toolkit (NLTK), Basics
 
Moose (Perl 5)
Moose (Perl 5)Moose (Perl 5)
Moose (Perl 5)
 
Introduction To Moose
Introduction To MooseIntroduction To Moose
Introduction To Moose
 
Procesamiento del lenguaje natural con python
Procesamiento del lenguaje natural con pythonProcesamiento del lenguaje natural con python
Procesamiento del lenguaje natural con python
 
MongoDB: Replication,Sharding,MapReduce
MongoDB: Replication,Sharding,MapReduceMongoDB: Replication,Sharding,MapReduce
MongoDB: Replication,Sharding,MapReduce
 
Automatically Spotting Cross-language Relations
Automatically Spotting Cross-language RelationsAutomatically Spotting Cross-language Relations
Automatically Spotting Cross-language Relations
 
You are in a maze of deeply nested maps, all alike
You are in a maze of deeply nested maps, all alikeYou are in a maze of deeply nested maps, all alike
You are in a maze of deeply nested maps, all alike
 
Introduction to Moose
Introduction to MooseIntroduction to Moose
Introduction to Moose
 
Intro To Moose
Intro To MooseIntro To Moose
Intro To Moose
 
Topological indices (t is) of the graphs to seek qsar models of proteins com...
Topological indices (t is) of the graphs  to seek qsar models of proteins com...Topological indices (t is) of the graphs  to seek qsar models of proteins com...
Topological indices (t is) of the graphs to seek qsar models of proteins com...
 
10b. Graph Databases Lab
10b. Graph Databases Lab10b. Graph Databases Lab
10b. Graph Databases Lab
 
Thoughts on MongoDB Analytics
Thoughts on MongoDB AnalyticsThoughts on MongoDB Analytics
Thoughts on MongoDB Analytics
 

Similar a jSession #3 - Krzysztof Czajkowski - Lombok in Java

AST Transformations at JFokus
AST Transformations at JFokusAST Transformations at JFokus
AST Transformations at JFokus
HamletDRC
 
CodeCamp Iasi 10 march 2012 - Practical Groovy
CodeCamp Iasi 10 march 2012 - Practical GroovyCodeCamp Iasi 10 march 2012 - Practical Groovy
CodeCamp Iasi 10 march 2012 - Practical Groovy
Codecamp Romania
 
AST Transformations
AST TransformationsAST Transformations
AST Transformations
HamletDRC
 

Similar a jSession #3 - Krzysztof Czajkowski - Lombok in Java (20)

Presentatie - Introductie in Groovy
Presentatie - Introductie in GroovyPresentatie - Introductie in Groovy
Presentatie - Introductie in Groovy
 
AST Transformations at JFokus
AST Transformations at JFokusAST Transformations at JFokus
AST Transformations at JFokus
 
CodeCamp Iasi 10 march 2012 - Practical Groovy
CodeCamp Iasi 10 march 2012 - Practical GroovyCodeCamp Iasi 10 march 2012 - Practical Groovy
CodeCamp Iasi 10 march 2012 - Practical Groovy
 
Groovy Ast Transformations (greach)
Groovy Ast Transformations (greach)Groovy Ast Transformations (greach)
Groovy Ast Transformations (greach)
 
Ast transformations
Ast transformationsAst transformations
Ast transformations
 
What's new in C# 6?
What's new in C# 6?What's new in C# 6?
What's new in C# 6?
 
AST Transformations
AST TransformationsAST Transformations
AST Transformations
 
Scala in a Java 8 World
Scala in a Java 8 WorldScala in a Java 8 World
Scala in a Java 8 World
 
Lombokの紹介
Lombokの紹介Lombokの紹介
Lombokの紹介
 
JavaScript Survival Guide
JavaScript Survival GuideJavaScript Survival Guide
JavaScript Survival Guide
 
Code smells (1).pptx
Code smells (1).pptxCode smells (1).pptx
Code smells (1).pptx
 
Best of build 2021 - C# 10 & .NET 6
Best of build 2021 -  C# 10 & .NET 6Best of build 2021 -  C# 10 & .NET 6
Best of build 2021 - C# 10 & .NET 6
 
Derping With Kotlin
Derping With KotlinDerping With Kotlin
Derping With Kotlin
 
Creating a Facebook Clone - Part XX.pdf
Creating a Facebook Clone - Part XX.pdfCreating a Facebook Clone - Part XX.pdf
Creating a Facebook Clone - Part XX.pdf
 
Guava et Lombok au Bordeaux JUG
Guava et Lombok au Bordeaux JUGGuava et Lombok au Bordeaux JUG
Guava et Lombok au Bordeaux JUG
 
Taking Perl to Eleven with Higher-Order Functions
Taking Perl to Eleven with Higher-Order FunctionsTaking Perl to Eleven with Higher-Order Functions
Taking Perl to Eleven with Higher-Order Functions
 
Introduzione a C#
Introduzione a C#Introduzione a C#
Introduzione a C#
 
Kick Start Jpa
Kick Start JpaKick Start Jpa
Kick Start Jpa
 
Hey Kotlin, How it works?
Hey Kotlin, How it works?Hey Kotlin, How it works?
Hey Kotlin, How it works?
 
Pim Elshoff "Technically DDD"
Pim Elshoff "Technically DDD"Pim Elshoff "Technically DDD"
Pim Elshoff "Technically DDD"
 

Último

+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 

Último (20)

+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdf
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 

jSession #3 - Krzysztof Czajkowski - Lombok in Java

Notas del editor

  1. W jaki sposób dodac Lomboka do projektu? Wystarczy dodać dependency do pom.xml i już, cała magia jest zrobiona, maven ściągnie odpowiedniego jara i można spokojnie używać w projekcie.
  2. Gdy projekt jest budowany przy użyciu Gradle, również można dodać do niego Lomboka. W zależności od wersji: Gradle 2.12 lub nowszy -> w pliku build.gradle w sekcji dependencies umieszczamy: compileOnly Gradle starszy -> w pliku build.gradle w sekcji dependencies umieszczamy: provided
  3. Annotation processing to narzęcie wbudowane w kompilator javy do skanowania i przetwarzania adnotacji podczas kompilacji. Można zarejestrować własny procesor adnotacji dla konkretnych adnotacji Procesor adnotacji dla konkretnych adnotacji bierze kod javy (lub byte code) i na jego podstawie generuje pliki (zazwyczaj *.java). Co to znaczy? Pozwala to generować kod. Wygenerowany kod jest w wygenerowanym pliku *.java. Oznacza to, że nie można zmieniać istniejącej klasy poprzez dodanie metody. Wygenerowany plik java będzie skompilowany przez kompilator (javac) jak każdy inny plik napisany ręcznie. Annotation processing is a tool build in javac for scanning and processing annotations at compile time. You can register your own annotation processor for certain annotations. An annotation processor for a certain annotation takes java code (or compiled byte code) as input and generate files (usually .java files) as output. What does that exactly means? You can generate java code! The generated java code is in a generated .java file. So you can not manipulate an existing java class for instance adding a method. The generated java file will be compiled by javac as any other hand written java source file.
  4. Adnotacje Getter i Setter służą do generowanie getterów i seterów, czyli to, gdzie możemy zaoszczędzić szczególnie dużo kodu. Adnotacje mogą być dodane na poziomie klasy, wtedy metody są generowane dla wszystkich pól, albo można wygenerować te metody tylko dla konkretnych pól.
  5. Adnotacje Getter i Setter służą do generowanie getterów i seterów, czyli to, gdzie możemy zaoszczędzić szczególnie dużo kodu. Adnotacje mogą być dodane na poziomie klasy, wtedy metody są generowane dla wszystkich pól, albo można wygenerować te metody tylko dla konkretnych pól.
  6. Adnotacje Getter i Setter służą do generowanie getterów i seterów, czyli to, gdzie możemy zaoszczędzić szczególnie dużo kodu. Adnotacje mogą być dodane na poziomie klasy, wtedy metody są generowane dla wszystkich pól, albo można wygenerować te metody tylko dla konkretnych pól.
  7. Generuje metody equals() i hashCode().
  8. Generuje metody equals() i hashCode().
  9. Generuje metody equals() i hashCode().
  10. Generuje metody equals() i hashCode().
  11. Generuje metody equals() i hashCode().
  12. Proste generacja metody toString().
  13. Proste generacja metody toString().
  14. Podstawowa adnotacja dodająca kod konstruktora bezargumentowego to NoArgsConstructor.
  15. Adnotacja NoArgsConstructor jest dodawana na poziomie deklaracji klasy.
  16. Adnotacja AllArgsConstructor generuje konstruktor z wszystkimi argumentami.
  17. Adnotacja AllArgsConstructor generuje konstruktor z wszystkimi argumentami.
  18. RequiredArgsConstructor – tworzy konstruktor z polami, które są wymagane – pola oznaczone jako final lub pola z adnotacja @NonNull. Można łączyć wiele adnotacji, więc wygenerować tylko jeden z kontstruktorów, wszystkie trzy lub dowolną ich kombinację, w zależności od naszych potrzeb. Oczywiście, można również dopisać inne, bardziej specyficzne konstruktory.
  19. RequiredArgsConstructor – tworzy konstruktor z polami, które są wymagane – pola oznaczone jako final lub pola z adnotacja @NonNull. Można łączyć wiele adnotacji, więc wygenerować tylko jeden z kontstruktorów, wszystkie trzy lub dowolną ich kombinację, w zależności od naszych potrzeb. Oczywiście, można również dopisać inne, bardziej specyficzne konstruktory.
  20. Adnotacja @Data generuje konstruktor bezargumentowy, gettery/setery wszystkich pól, metody equals, hashCode, toString.
  21. Połączenie wielu adnotacji w jednej klasie. Jak widać, Gettery dla wszystkich pól, Settery tylko dla dwóch pól – firstName, lastName. Do tego metody equals(), hashCode() i toString(). Konstruktory nie zostały wygenerowane, jedynie konstruktor napisany z palca. Pokazać jaka róznica w szybkości napisania klasy bez lomboka i z lombokiem.
  22. A method annotated with @Builder (from now on called the target) causes the following 7 things to be generated: - An inner static class named SuperheroBuilder, with the same type arguments as the static method (called the builder). In the builder: One private non-static non-final field for each parameter of the target. In the builder: A package private no-args empty constructor. In the builder: A 'setter'-like method for each parameter of the target: It has the same type as that parameter and the same name. It returns the builder itself, so that the setter calls can be chained, as in the above example. In the builder: A build() method which calls the method, passing in each field. It returns the same type that the target returns. In the builder: A sensible toString() implementation. In the class containing the target: A builder() method, which creates a new instance of the builder.
  23. A method annotated with @Builder (from now on called the target) causes the following 7 things to be generated: - An inner static class named SuperheroBuilder, with the same type arguments as the static method (called the builder). In the builder: One private non-static non-final field for each parameter of the target. In the builder: A package private no-args empty constructor. In the builder: A 'setter'-like method for each parameter of the target: It has the same type as that parameter and the same name. It returns the builder itself, so that the setter calls can be chained, as in the above example. In the builder: A build() method which calls the method, passing in each field. It returns the same type that the target returns. In the builder: A sensible toString() implementation. In the class containing the target: A builder() method, which creates a new instance of the builder.
  24. A method annotated with @Builder (from now on called the target) causes the following 7 things to be generated: - An inner static class named SuperheroBuilder, with the same type arguments as the static method (called the builder). In the builder: One private non-static non-final field for each parameter of the target. In the builder: A package private no-args empty constructor. In the builder: A 'setter'-like method for each parameter of the target: It has the same type as that parameter and the same name. It returns the builder itself, so that the setter calls can be chained, as in the above example. In the builder: A build() method which calls the method, passing in each field. It returns the same type that the target returns. In the builder: A sensible toString() implementation. In the class containing the target: A builder() method, which creates a new instance of the builder.
  25. Dlaczego używać projektu Lombok w projekcie? Trzy rzeczy. Mniej kodu. I to kodu, który musimy napisać i zajmuje dużo czasu, nawet jeśli używamy IDE do wygenerowania go, zajmuje to czas, który możemy spożytkować lepiej i bardziej produktywnie. Kod klasy jest czytelniejszy, co wynika z punktu pierwszego. Jak wiadomo, większość czasu poświęcamy na czytanie kodu, nie na pisanie, a zredukowanie liczby linii kodu ułatwia zapoznanie się z klasą. Szybsze programowanie. Dużo szybciej jest dodać adnotacje zamiast pisania ciała metody.
  26. POL 1. Niezdolność do wykrycia konstruktora klasy bazowej. To znaczy, jeżeli klasa bazowa nie posiada defaultowego konstruktora, żadna klasa dziedzicząca ni emoże użyć adnotacji @Data bez bezpośredniego napisania konstruktora, który użyje dostępnego konstruktora klasy bazowej. 2. Lombok jest ściśle powiązany z kompilatorem Javy. Ponieważ API procesora adnotacji pozwala jedynie na tworzenie nowych plików podczas kompilacji (nie modyfikację istniejących) lombok używa API jako punktu wejściowego (entry point) żeby zmodyfikować kompilator javy. Powoduje to, że użyte jest niepubliczne API. Użycie Lomboka może sprawić, że przy upgradzie kompilatora nasz kod przestanie działać. ENG 1. One important problem is the inability to detect the constructors of a superclass. This means that if a superclass has no default constructor any subclasses cannot use the @Data annotation without explicitly writing a constructor to make use of the available superclass constructor. . 2. A limitation of Lombok is the fact that it is closely tied to the java compiler. Since the annotation processor API only allows creation of new files during the compilation (and not the modification of the existing files) lombok uses that API as a entry point to modify the java compiler. Unfortunately these modifications of the compiler make heavy usage of non-public APIs. Using lombok may be a good idea but you must be aware that upgrading your compiler may broke your code.