- Forward


Run-Time Processing of Annotations
in Java


Prof. David Bernstein
James Madison University

Computer Science Department
bernstdh@jmu.edu

Print

Review
Back SMYC Forward
  • Purpose:
    • Annotations provide information/data about a program
  • Defining:
    • Annotations are defined using an interface-like syntax
Run-Time Processing
Back SMYC Forward
  • The Process:
    • Use reflection
  • The Details:
    • Get the target of the annotation (e.g., the Class, or Method object)
    • Call the getAnnotation() method
An Example
Back SMYC Forward
  • The Setting:
    • We want to use JUnit to test a heuristic; some of the tests are critical (i.e., normal tests), some of are methods that may or may not produce the correct answer even when "working"
  • What's Needed:
    • An annotation
    • A TestExecutionListener
An Example (cont.)
Back SMYC Forward

The Annotation

javaexamples/annotations/NonCritical.java
 
An Example (cont.)
Back SMYC Forward

The Processor

javaexamples/annotations/CategorizedTestExecutionListener.java
 
There's Always More to Learn
Back -