SlideShare une entreprise Scribd logo
1  sur  86
Annotations
Unleashing the power of Java
Danilo De Luca
@danilodeluca
danilo.luca@dextra-sw.com
Luan Nico
@luanpotter
luannico27@gmail.com
Annotations - O que são?
➔Meta documentação do código
Annotations - O que são?
➔Meta documentação do código
@Override
public void toString() { /* ... */ }
Annotations - Default Annotations
@Override
@Deprecated
@SupressWarnings({ "unchecked" /* , ... */ })
@SafeVarargs
@FunctionalInterface
Annotations - Default Annotations
@Override
@Deprecated
@SupressWarnings({ "unchecked" /* , ... */ })
@SafeVarargs -> stackoverflow.com/questions/14231037
@FunctionalInterface
Annotations - Default Annotations
@Override
@Deprecated
@SupressWarnings({ "unchecked" /* , ... */ })
@SafeVarargs -> stackoverflow.com/questions/14231037
@FunctionalInterface -> Java 8 (Consumer, Function, …)
Annotations - Creating Annotations!
Annotations - Creating Annotations!
public @interface MyShinyAnnotation {
/* ... */
}
Annotations - Annotating Annotations
Annotations - Annotating Annotations
@Retention ◀
@Target
@Documented
@Inherited
Annotations - RetentionPolicy
RetentionPolicy.SOURCE
RetentionPolicy.CLASS
RetentionPolicy.RUNTIME
Annotations - RetentionPolicy
RetentionPolicy.SOURCE - @Override
RetentionPolicy.CLASS
RetentionPolicy.RUNTIME
Annotations - RetentionPolicy
RetentionPolicy.SOURCE - @Override
RetentionPolicy.CLASS - bytecode libs
RetentionPolicy.RUNTIME
Annotations - RetentionPolicy
RetentionPolicy.SOURCE - @Override
RetentionPolicy.CLASS - bytecode libs
RetentionPolicy.RUNTIME - @Deprecated
Annotations - Creating Annotations!
@Retention(RetentionPolicy.RUNTIME)
public @interface MyShinyAnnotation {
/* ... */
}
Annotations - Annotating Annotations
@Retention
@Target ◀
@Documented
@Inherited
Annotations - ElementType
ElementType.ANNOTATION_TYPE
ElementType.CONSTRUCTOR
ElementType.FIELD
ElementType.LOCAL_VARIABLE
ElementType.METHOD
ElementType.PACKAGE
ElementType.PARAMETER
ElementType.TYPE
Annotations - ElementType
ElementType.ANNOTATION_TYPE
ElementType.CONSTRUCTOR
ElementType.FIELD
ElementType.LOCAL_VARIABLE
ElementType.METHOD
ElementType.PACKAGE
ElementType.PARAMETER
ElementType.TYPE
ElementType.TYPE_PARAMETER NEW
ElementType.TYPE_USE NEW
Annotations - Creating Annotations!
@Target({ TYPE, METHOD, FIELD })
@Retention(RetentionPolicy.RUNTIME)
public @interface MyShinyAnnotation {
/* ... */
}
Annotations - Annotating Annotations
@Retention
@Target
@Documented ◀
@Inherited
Annotations - Annotating Annotations
@Retention
@Target
@Documented
@Inherited ◀ [class only]
Annotations - Annotating Annotations
@Retention
@Target
@Documented
@Inherited
@Repeatable ◀ NEW
Annotations - Elements
Annotations - Elements
@Target({ TYPE, METHOD, FIELD })
@Retention(RetentionPolicy.RUNTIME)
public @interface MyShinyAnnotation {
String value();
int intValue() default 12;
}
Annotations - Elements
@MyShinyAnnotation
@MyShinyAnnotation()
@MyShinyAnnotation(value = "a")
@MyShinyAnnotation("a")
@MyShinyAnnotation(value = "a", intValue = 7)
@MyShinyAnnotation("a", intValue = 7)
Annotations - Elements
@MyShinyAnnotation
@MyShinyAnnotation() : todos os elements são obrigatórios (salvo default)
@MyShinyAnnotation(value = "a")
@MyShinyAnnotation("a")
@MyShinyAnnotation(value = "a", intValue = 7)
@MyShinyAnnotation("a", intValue = 7)
Annotations - Elements
@MyShinyAnnotation
@MyShinyAnnotation() : todos os elements são obrigatórios (salvo default)
@MyShinyAnnotation(value = "a") : ok
@MyShinyAnnotation("a") : ok
@MyShinyAnnotation(value = "a", intValue = 7)
@MyShinyAnnotation("a", intValue = 7)
Annotations - Elements
@MyShinyAnnotation
@MyShinyAnnotation() : todos os elements são obrigatórios (salvo default)
@MyShinyAnnotation(value = "a") : ok
@MyShinyAnnotation("a") : ok
@MyShinyAnnotation(value = "a", intValue = 7) :ok
@MyShinyAnnotation("a", intValue = 7)
Annotations - Elements
@MyShinyAnnotation
@MyShinyAnnotation() : todos os elements são obrigatórios (salvo default)
@MyShinyAnnotation(value = "a") : ok
@MyShinyAnnotation("a") : ok
@MyShinyAnnotation(value = "a", intValue = 7) :ok
@MyShinyAnnotation("a", intValue = 7) : nok
Annotations - Uses
Annotations - Uses
Documentação - Evolução Javadoc
// Author: John Doe
// Date: 3/17/2002
// Current revision: 6
// Last modified: 4/12/2004
// By: Jane Doe
// Reviewers: Alice, Bill, Cindy
public class MyPojo { /* ... */ }
Annotations - Uses
Documentação - Evolução Javadoc
// Author: John Doe
// Date: 3/17/2002
// Current revision: 6
// Last modified: 4/12/2004
// By: Jane Doe
// Reviewers: Alice, Bill, Cindy
public class MyPojo { /* ... */ }
@ClassPreamble(
author = "John Doe",
date = "3/17/2002",
currentRevision = 6,
lastModified = "4/12/2004",
lastModifiedBy = "Jane Doe",
reviewers = { "Alice", "Bob", "Cindy" }
)
public class MyPojo { /* ... */ }
Annotations - Uses
Documentação - Evolução Javadoc
// Author: John Doe
// Date: 3/17/2002
// Current revision: 6
// Last modified: 4/12/2004
// By: Jane Doe
// Reviewers: Alice, Bill, Cindy
public class MyPojo { /* ... */ }
@ClassPreamble(
author = "John Doe",
date = "3/17/2002",
currentRevision = 6,
lastModified = "4/12/2004",
lastModifiedBy = "Jane Doe",
reviewers = { "Alice", "Bob", "Cindy" }
)
public class MyPojo { /* ... */ }
➔ Easily ‘parseable’!
➔ Standardized!
➔ Type safe!*
*Well, sort of…
➔ Required (compile errors)
Annotations - Uses
Solução mais simples...
Annotations - Uses
Solução mais simples...
GIT
Annotations - Uses
Documentação - Casos Reais
Annotations - Uses
Documentação - Casos Reais
@DroolsUsage
@FailingTest
Annotations - Uses
Runtime Analysis
Annotations - Uses
Runtime Analysis
➔ Hibernate, Spring, Drools, yawp.io
Annotations - Uses
Runtime Analysis
➔ Hibernate, Spring, Drools, yawp.io
Annotations over xml hell!
Annotations - Uses
Annotation Preprocessing
Annotations - Uses
Annotation Preprocessing LATER
Annotations - Uses
Documentação
Runtime Analysis
Annotation Preprocessing
Annotations - Limitations
Annotations - Limitations
★ Valid element types
Annotations - Limitations
★ Valid element types
String Primitives
Enums Annotations
Class Arrays of those
Annotations - Limitations
★ Valid element types
String Primitives
Enums Annotations
Class Arrays of those
>> Use enum’s or String’s
➔ Date -> String
➔ Comparator -> ComparatorType [could be a Class here too]
>> Use other annotations to group fields
>> But no generic enum nor annotation! [Enum, Annotation]
Annotations - Limitations
★ Compile-time constant values
Annotations - Limitations
★ Compile-time constant values
@Source(value = "xpto")
public static String randomString() { /* ... */ }
@Source(value = randomString())
public static String readFromFile() { /* ... */ }
@Source(value = readFromFile())
public static String readFromDatabase() { /* ... */ }
@Source(value = readFromDatabase())
Annotations - Limitations
★ Compile-time constant values
@Source(value = "xpto") : ok
public static String randomString() { /* ... */ }
@Source(value = randomString()) : nok
public static String readFromFile() { /* ... */ }
@Source(value = readFromFile()) : nok
public static String readFromDatabase() { /* ... */ }
@Source(value = readFromDatabase()) : nok
Annotations - Limitations
★ Compile-time constant values
@Source(value = "xpto") : ok
static final String myValue = "xpt";
@Source(value = myValue + "o")
static final String myValue = readFromDatabase();
@Source(value = myValue + "o")
static final String[] myValues = { "xpto" };
@Source(value = myValues[0])
Annotations - Limitations
★ Compile-time constant values
@Source(value = "xpto") : ok
static final String myValue = "xpt";
@Source(value = myValue + "o") : ok
static final String myValue = readFromDatabase();
@Source(value = myValue + "o")
static final String[] myValues = { "xpto" };
@Source(value = myValues[0])
Annotations - Limitations
★ Compile-time constant values
@Source(value = "xpto") : ok
static final String myValue = "xpt";
@Source(value = myValue + "o") : ok
static final String myValue = readFromDatabase();
@Source(value = myValue + "o") : nok
static final String[] myValues = { "xpto" };
@Source(value = myValues[0])
Annotations - Limitations
★ Compile-time constant values
@Source(value = "xpto") : ok
static final String myValue = "xpt";
@Source(value = myValue + "o") : ok
static final String myValue = readFromDatabase();
@Source(value = myValue + "o") : nok
static final String[] myValues = { "xpto" };
@Source(value = myValues[0]) : nok
Annotations - Limitations
★ No inheritance
>> Annotate annotations with annotations
@Validator(clazz = Object.class)
public @interface NotNull { /* ... */ }
Annotations - Limitations
★ No inheritance
>> Annotate annotations with annotations
@Validator(clazz = Object.class)
public @interface NotNull { /* ... */ }
>> Extract repeated code to other classes
>> Make broad annotations with specializing optional parameters
New to Java 8
❖ Repeating Annotations
❖ Type Annotations
Repeating Annotations
Repeating Annotations
@Allow(Roles.USER)
@Allow(Roles.ADMIN)
public void process(Data data) { /* … */ }
Repeating Annotations
@Allow({ Roles.USER, Roles.ADMIN })
public void process(Data data) { /* … */ }
Repeating Annotations
@Allow(value = Roles.USER, access = Access.READ_ONLY)
@Allow(value = Roles.ADMIN, access = Access.READ_WRITE)
public void process(Data data) { /* … */ }
Repeating Annotations
@Allows({
@Allow(value = Roles.USER, access = Access.READ_ONLY)
@Allow(value = Roles.ADMIN, access = Access.READ_WRITE)
})
public void process(Data data) { /* … */ }
Repeating Annotations
@Repeatable(Allows.class)
public @interface Allow {
Role value();
Access access();
}
public @interface Allows {
Allow[] value();
}
Repeating Annotations
@Allow(value = Roles.USER, access = Access.READ_ONLY)
@Allow(value = Roles.ADMIN, access = Access.READ_WRITE)
public void process(Data data) { /* … */ }
Type Annotations
Type Annotations
★ ElementType.TYPE_PARAMETER : tipos usados como generics
★ ElementType.TYPE_USE : qualquer menção a um tipo
Type Annotations
★ List<@Numeric String> phones;
★ Map<@NonEmpty String, @Adult Person> peopleByName;
public void test() {
@NotNull String a = "Hi!";
// ….
}
Type Annotations
★ This can be used for several things:
○ Checkers
○ Static code validation
○ Model Validation
Type Annotations
Example!
<dependency>
<groupId>xyz.luan</groupId>
<artifactId>reflection-utils</artifactId>
<version>0.7.1</version>
</dependency>
Annotation Preprocessing
Annotation Preprocessing
➔Etapas adicionais de compilação
controladas via Annotations
➔Exemplo:
◆ projectlombok.org / github.com/rzwitserloot/lombok
◆ FragmentArgs / ButterKnife [android]
Annotation Preprocessor
➔Project Lombok
public class MyBoringModel {
private String field;
public String getField() {
return this.field;
}
}
Annotation Preprocessor
➔Project Lombok
public class MyBoringModel {
@Getter private String field;
}
➔ @Getter, @Setter, @ToString, @EqualsAndHashCode → @Data
➔ @SneakyThrows, @UtilityClass, @Cleanup
➔Muito mais!
➔projectlombok.org/features
Annotation Preprocessing
➔Como funciona?
◆ Preprocessors extend AbstractProcessor
◆ Implementam os métodos usando uma API análoga
a de Reflection
◆ Registram-se no META-INF
◆ javac sobe uma vm e roda os processadores
registrados em turnos
Annotation Preprocessing
➔Na prática
◆ Baixe o jar da biblioteca e coloque no classpath do
javac
Annotation Preprocessing
➔Na prática
◆ ✓ Baixe o jar da biblioteca e coloque no classpath
do javac
Annotation Preprocessing
➔Na prática
◆ ✓ Baixe o jar da biblioteca e coloque no classpath
do javac
◆ Adicione a dependência no maven/gradle/etc
Annotation Preprocessing
➔Na prática
◆ ✓ Baixe o jar da biblioteca e coloque no classpath
do javac
◆ ✓ Adicione a dependência no maven/gradle/etc
Annotation Preprocessing
➔Na prática
◆ ✓ Baixe o jar da biblioteca e coloque no classpath
do javac
◆ ✓ Adicione a dependência no maven/gradle/etc
➔Precisa ser uma lib separada [META-INF]
➔Precisa habilitar annotation preprocessing
em algumas IDEs (javac faz por padrão)
Annotation Preprocessor
➔Possibilidades
◆ Análise de código (dar erros e warnings...)
◆ Gerar métodos, campos, classes, qualquer coisa
➔Limitações
◆ Triggerado por annotations [processamento em
rodadas]
➔“Problemas”
◆ Excessivamente poderoso
Annotation Preprocessor
➔Como fazer?
◆ Exemplo Codigo
Annotation Preprocessing
<dependencies>
<dependency>
<groupId>com.google.auto.service</groupId>
<artifactId>auto-service</artifactId>
<version>1.0-rc4</version>
</dependency>
</dependencies>
Annotation Preprocessing
➔Extremamente poderoso!
◆ With great power comes great responsibility
➔API razoavelmente feia
➔Podemos juntar com Reflection
◆ Preprocess in compile-time
◆ Reflection in run-time
➔Possibilidades são infinitas
Dúvidas?
Danilo De Luca
@danilodeluca
danilo.luca@dextra-sw.com
Luan Nico
@luanpotter
luannico27@gmail.com

Contenu connexe

Similaire à Java Annotations and Pre-processing

Java Annotation Processing: A Beginner Walkthrough
Java Annotation Processing: A Beginner WalkthroughJava Annotation Processing: A Beginner Walkthrough
Java Annotation Processing: A Beginner WalkthroughMahfuz Islam Bhuiyan
 
PhpUnit - The most unknown Parts
PhpUnit - The most unknown PartsPhpUnit - The most unknown Parts
PhpUnit - The most unknown PartsBastian Feder
 
Php unit the-mostunknownparts
Php unit the-mostunknownpartsPhp unit the-mostunknownparts
Php unit the-mostunknownpartsBastian Feder
 
international PHP2011_Bastian Feder_The most unknown Parts of PHPUnit
international PHP2011_Bastian Feder_The most unknown Parts of PHPUnitinternational PHP2011_Bastian Feder_The most unknown Parts of PHPUnit
international PHP2011_Bastian Feder_The most unknown Parts of PHPUnitsmueller_sandsmedia
 
Programming Android Application in Scala.
Programming Android Application in Scala.Programming Android Application in Scala.
Programming Android Application in Scala.Brian Hsu
 
Ast transformations
Ast transformationsAst transformations
Ast transformationsHamletDRC
 
Davide Cerbo - Kotlin: forse è la volta buona - Codemotion Milan 2017
Davide Cerbo - Kotlin: forse è la volta buona - Codemotion Milan 2017 Davide Cerbo - Kotlin: forse è la volta buona - Codemotion Milan 2017
Davide Cerbo - Kotlin: forse è la volta buona - Codemotion Milan 2017 Codemotion
 
Core java concepts
Core    java  conceptsCore    java  concepts
Core java conceptsChikugehlot
 
The Swift Compiler and Standard Library
The Swift Compiler and Standard LibraryThe Swift Compiler and Standard Library
The Swift Compiler and Standard LibrarySantosh Rajan
 
What's new in PHP 8.0?
What's new in PHP 8.0?What's new in PHP 8.0?
What's new in PHP 8.0?Nikita Popov
 
Nikita Popov "What’s new in PHP 8.0?"
Nikita Popov "What’s new in PHP 8.0?"Nikita Popov "What’s new in PHP 8.0?"
Nikita Popov "What’s new in PHP 8.0?"Fwdays
 
Android Automated Testing
Android Automated TestingAndroid Automated Testing
Android Automated Testingroisagiv
 
Intro to scala
Intro to scalaIntro to scala
Intro to scalaJoe Zulli
 
Core Java Concepts
Core Java ConceptsCore Java Concepts
Core Java Conceptsmdfkhan625
 
Unit testing en iOS @ MobileCon Galicia
Unit testing en iOS @ MobileCon GaliciaUnit testing en iOS @ MobileCon Galicia
Unit testing en iOS @ MobileCon GaliciaRobot Media
 
An introduction to Raku
An introduction to RakuAn introduction to Raku
An introduction to RakuSimon Proctor
 
Introduction to Scala for JCConf Taiwan
Introduction to Scala for JCConf TaiwanIntroduction to Scala for JCConf Taiwan
Introduction to Scala for JCConf TaiwanJimin Hsieh
 

Similaire à Java Annotations and Pre-processing (20)

Java Annotation Processing: A Beginner Walkthrough
Java Annotation Processing: A Beginner WalkthroughJava Annotation Processing: A Beginner Walkthrough
Java Annotation Processing: A Beginner Walkthrough
 
PhpUnit - The most unknown Parts
PhpUnit - The most unknown PartsPhpUnit - The most unknown Parts
PhpUnit - The most unknown Parts
 
Java
JavaJava
Java
 
Php unit the-mostunknownparts
Php unit the-mostunknownpartsPhp unit the-mostunknownparts
Php unit the-mostunknownparts
 
international PHP2011_Bastian Feder_The most unknown Parts of PHPUnit
international PHP2011_Bastian Feder_The most unknown Parts of PHPUnitinternational PHP2011_Bastian Feder_The most unknown Parts of PHPUnit
international PHP2011_Bastian Feder_The most unknown Parts of PHPUnit
 
Programming Android Application in Scala.
Programming Android Application in Scala.Programming Android Application in Scala.
Programming Android Application in Scala.
 
55j7
55j755j7
55j7
 
Ast transformations
Ast transformationsAst transformations
Ast transformations
 
Davide Cerbo - Kotlin: forse è la volta buona - Codemotion Milan 2017
Davide Cerbo - Kotlin: forse è la volta buona - Codemotion Milan 2017 Davide Cerbo - Kotlin: forse è la volta buona - Codemotion Milan 2017
Davide Cerbo - Kotlin: forse è la volta buona - Codemotion Milan 2017
 
Play á la Rails
Play á la RailsPlay á la Rails
Play á la Rails
 
Core java concepts
Core    java  conceptsCore    java  concepts
Core java concepts
 
The Swift Compiler and Standard Library
The Swift Compiler and Standard LibraryThe Swift Compiler and Standard Library
The Swift Compiler and Standard Library
 
What's new in PHP 8.0?
What's new in PHP 8.0?What's new in PHP 8.0?
What's new in PHP 8.0?
 
Nikita Popov "What’s new in PHP 8.0?"
Nikita Popov "What’s new in PHP 8.0?"Nikita Popov "What’s new in PHP 8.0?"
Nikita Popov "What’s new in PHP 8.0?"
 
Android Automated Testing
Android Automated TestingAndroid Automated Testing
Android Automated Testing
 
Intro to scala
Intro to scalaIntro to scala
Intro to scala
 
Core Java Concepts
Core Java ConceptsCore Java Concepts
Core Java Concepts
 
Unit testing en iOS @ MobileCon Galicia
Unit testing en iOS @ MobileCon GaliciaUnit testing en iOS @ MobileCon Galicia
Unit testing en iOS @ MobileCon Galicia
 
An introduction to Raku
An introduction to RakuAn introduction to Raku
An introduction to Raku
 
Introduction to Scala for JCConf Taiwan
Introduction to Scala for JCConf TaiwanIntroduction to Scala for JCConf Taiwan
Introduction to Scala for JCConf Taiwan
 

Dernier

A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
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 2024Rafal Los
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
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...Neo4j
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?Igalia
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
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 BusinessPixlogix Infotech
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 

Dernier (20)

A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
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
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
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...
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
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
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 

Java Annotations and Pre-processing

Notes de l'éditeur

  1. http://markup.su/highlighter/
  2. http://markup.su/highlighter/
  3. [DanDan]
  4. [DanDan]
  5. [DanDan] SafeVarargs-> falar para o compilador que quando usar metodo com bla(T… asd) ignorar o aviso de problema
  6. [DanDan] SafeVarargs-> falar para o compilador que quando usar metodo com bla(T… asd) ignorar o aviso de problema
  7. [DanDan] FunctionalInterface -> Criacao de uma interface para lambdas Essas são todas as annotations do JDK, exceto as relacionadas à criação de annotations
  8. [Luan]
  9. [Luan] they are interfaces!
  10. [Luan]
  11. [Luan]
  12. [Luan]
  13. [Luan] RetentionPolicy.SOURCE: Discard during the compile. These annotations don't make any sense after the compile has completed, so they aren't written to the bytecode. Example: @Override, @SuppressWarnings Server somente para documentacao, na compilacao sera jogada fora
  14. [Luan] RetentionPolicy.CLASS: Discard during class load. Useful when doing bytecode-level post-processing. Somewhat surprisingly, this is the default. Não deixar vc acessar por reflection e runtime e nem por pre-processamento, so serve para libs que altera direto o bytecode
  15. [Luan] RetentionPolicy.RUNTIME: Do not discard. The annotation should be available for reflection at runtime. Example: @Deprecated Esta sempre disponivel inclusive em runtime, reflection e preprocessamento.
  16. [Luan]
  17. [Luan] Target -> Onde pode usar a annotation
  18. [Luan] they are interfaces!
  19. [Luan] Type = qualquer declaracao de tipo
  20. [Luan] import static ElementType!
  21. [Luan] Se ela tiver o @Documented no javadoc ela vai continuar la
  22. [Luan] Inherited = Herdado, hereditario Se classe pai com @Bla, e bla for @Inherited, seus filhos vao ter essa annotation
  23. [Luan] @Repeatable -> poder repetir a msm annotaiton em um uso.
  24. [Luan]
  25. [Luan] Sao metodos, mas em particular chamamos de elementos
  26. [Luan] Quem ai saberia dizer quais funcionam e quais não e pq?
  27. [Luan] they are interfaces!
  28. [Luan]
  29. [Luan]
  30. [Luan] Explicar o pq o ultimo não vai dar ce
  31. [DanDan]
  32. [DanDan]
  33. [DanDan]
  34. [DanDan]
  35. [DanDan]
  36. [DanDan] Git serve para resolver o problema da annotation de documentacao.
  37. [DanDan]
  38. [DanDan] Duas annotation de 100% de documentacao, não sao runtime.
  39. [DanDan] Quando usamos as annotations em runtime para definir o comportamento da aplicacao Assim podemos evitar o uso de XMLs
  40. [DanDan] Injeccao de dependencias, @Entites,
  41. [DanDan] Injeccao de dependencias, @Entites,
  42. [DanDan]
  43. [DanDan]
  44. [DanDan]
  45. [DanDan]
  46. [DanDan]
  47. [DanDan] Type safe limitado a esses seis tipos: String, enums, class, primitivies, annotations, arrays of those Pq inicialmente as annotations deveriam ser usadas para documentacao, Deve usar valores constantes, não temo como usar uma instancia de alguma classe com valor constante. Annotation nunca deve rodar um codigo!
  48. [DanDan] Class não pode ser Generics!
  49. [DanDan]
  50. [DanDan] O valor deve ser uma constante de compilacao, o uso da annotation nunca pode rodar um codigo
  51. [DanDan]
  52. [DanDan]
  53. [DanDan]
  54. [DanDan] Pode somar strings entre coisas que sao constatnes
  55. [DanDan] Apenasr do array ser static final os elementos dele não sao constantes, em algum lugar fazer myValues[0] = “ASDSDA”
  56. [DanDan]
  57. [DanDan] Uma annotation não herdar com outra,
  58. [Luan]
  59. [Luan]
  60. [Luan]
  61. [Luan]
  62. [Luan]
  63. [Luan]
  64. [Luan]
  65. [Luan]
  66. [Luan]
  67. [Luan] O ElementType.TYPE_PARAMETER indica que a anotação pode ser usada na declaração de tipos, tais como: classes ou métodos com generics ou ainda junto de caracteres coringa em declarações de tipos anônimos. O ElementType.TYPE_USE indica que a anotação pode ser aplicada em qualquer ponto que um tipo é usado, por exemplo em declarações, generics e conversões de tipos (casts).
  68. [Luan]
  69. [Luan]
  70. [DanDan live code]
  71. [Luan]
  72. [Luan]
  73. [Luan]
  74. [Luan]
  75. [Luan]
  76. [Luan]
  77. [Luan]
  78. [Luan]
  79. [Luan]
  80. [Luan]
  81. [Luan]
  82. [Luan]
  83. [Luan]
  84. [Luan]
  85. http://markup.su/highlighter/