SlideShare ist ein Scribd-Unternehmen logo
1 von 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

Weitere ähnliche Inhalte

Ähnlich wie Java Annotations and Pre-processing

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
 
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
 
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
 
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
 
Terence Barr - jdk7+8 - 24mai2011
Terence Barr - jdk7+8 - 24mai2011Terence Barr - jdk7+8 - 24mai2011
Terence Barr - jdk7+8 - 24mai2011Agora Group
 
Serializing EMF models with Xtext
Serializing EMF models with XtextSerializing EMF models with Xtext
Serializing EMF models with Xtextmeysholdt
 

Ähnlich wie Java Annotations and Pre-processing (20)

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
 
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?"
 
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?
 
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
 
Terence Barr - jdk7+8 - 24mai2011
Terence Barr - jdk7+8 - 24mai2011Terence Barr - jdk7+8 - 24mai2011
Terence Barr - jdk7+8 - 24mai2011
 
Serializing EMF models with Xtext
Serializing EMF models with XtextSerializing EMF models with Xtext
Serializing EMF models with Xtext
 

Kürzlich hochgeladen

Platformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityPlatformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityWSO2
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...Zilliz
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native ApplicationsWSO2
 
Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Zilliz
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesrafiqahmad00786416
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...apidays
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxRustici Software
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyKhushali Kathiriya
 
Six Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal OntologySix Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal Ontologyjohnbeverley2021
 
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Bhuvaneswari Subramani
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsNanddeep Nachan
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamUiPathCommunity
 
Vector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxVector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxRemote DBA Services
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusZilliz
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodJuan lago vázquez
 
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 WorkerThousandEyes
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfOrbitshub
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businesspanagenda
 

Kürzlich hochgeladen (20)

Platformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityPlatformless Horizons for Digital Adaptability
Platformless Horizons for Digital Adaptability
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
 
Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Six Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal OntologySix Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal Ontology
 
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
+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...
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 
Vector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxVector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptx
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
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
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 

Java Annotations and Pre-processing

Hinweis der Redaktion

  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/