Core Java Advanced LiveLessons

Annotations

Copyright © Cay S. Horstmann 2016

Know how to annotate declarations and type uses

What Are Annotations?

Annotation Elements

Syntax for Annotation Elements

Multiple and Repeated Annotations

Annotating Declarations

Annotating Type Uses

Explicit Receivers

Define your own annotations

Annotation Types

Default Values

Be familiar with the annotations in the Java API

Annotations for Compiling

lesson05/standardAnnotations

Meta-Annotations

Repeatable Annotations

Understand how annotations are processed

Processing Annotations at Runtime

Implementing Runtime Annotation Processing

lesson05/runtime

Using Annotations to Generate Source Code

Generating Code for the ToStrings Class

Annotation Processors

lesson05/sourcelevel

javac com/horstmann/annotations/ToStringAnnotationProcessor.java
javac -processor com.horstmann.annotations.ToStringAnnotationProcessor sourcelevel/*.java
java sourcelevel.SourceLevelAnnotationDemo

Modifying Classes at Load Time

Bytecode Engineering

lesson05/Logging agent

javac -classpath .:../asm-5.1/lib/\* bytecodeAnnotations/EntryLoggingAgent.java
jar cvfm bytecodeAnnotations/EntryLoggingAgent.jar bytecodeAnnotations/EntryLoggingAgent.mf \
bytecodeAnnotations/Entry*.class
javac set/SetTest.java
java -javaagent:bytecodeAnnotations/EntryLoggingAgent.jar=set.Item -classpath .:../asm-5.1/lib/\* set.SetTest