Java Tutorials - Herong's Tutorial Examples - v8.22, by Herong Yang
No-Element (Marker) Annotation Invocation
This section provides a tutorial example on how to use the marker format in annotation invocation statements, if no annotation elements are needed.
If an annotation invocation statement has no annotation elements, you can omit the empty parentheses, ().
An annotation invocation statement with no annotation elements is called "Marker Annotation", because it appears like a marker in front of the targeted program construct.
Here is a sample program that shows you how to use the marker format in annotation invocation statements, if no annotation elements are needed.
/* MarkerAnnotation.java * Copyright (c) HerongYang.com. All Rights Reserved. */ class MarkerAnnotation { // Annotation declarations @interface Herong { String value() default "Herong"; String email() default "herong@nowhere.com"; } @interface John { String value() default "John"; String email() default "john@nowhere.com"; } // Annotation invocation - Marker format @Herong public static void main(String[] arg) { printMsg("Hello world!"); } // Annotation invocation - Normal format @John() public static void printMsg(String msg) { System.out.println(msg); } }
If you compile and run the program, you will get:
herong> java MarkerAnnotation.java Hello world!
Table of Contents
Execution Process, Entry Point, Input and Output
Primitive Data Types and Literals
Bits, Bytes, Bitwise and Shift Operations
Managing Bit Strings in Byte Arrays
Reference Data Types and Variables
StringBuffer - The String Buffer Class
System Properties and Runtime Object Methods
Generic Classes and Parameterized Types
Generic Methods and Type Inference
Lambda Expressions and Method References
Java Modules - Java Package Aggregation
Execution Threads and Multi-Threading Java Programs
ThreadGroup Class and "system" ThreadGroup Tree
Synchronization Technique and Synchronized Code Blocks
Deadlock Condition Example Programs
Garbage Collection and the gc() Method
Assert Statements and -ea" Option
►Annotation Statements and Declarations
Default Values for Annotation Elements
Single-Element Annotation Invocation
►No-Element (Marker) Annotation Invocation