How do I annotate a class or method?

This example show you how to use the HelloAnnotation annotation on the previous example code, How do I create a simple annotation?. We add the HelloAnnotation annotation to our class and its methods.

package org.kodejava.lang.annotation;

@HelloAnnotation(value = "Good Morning", greetTo = "Universe")
public class HelloAnnotationExample {
    public static void main(String[] args) {
        HelloAnnotationExample hello = new HelloAnnotationExample();
        hello.sayHi();
        hello.sayHello();
    }

    @HelloAnnotation(value = "Hi there", greetTo = "Alice")
    private void sayHi() {
    }

    @HelloAnnotation(value = "Hello there", greetTo = "Bob")
    private void sayHello() {
    }
}
Wayan

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.