How do I annotate a class or method?

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

package org.kodejava.example.annotation;

@HelloAnno(value = "Good Morning", greetTo = "Universe")
public class HelloAnnoExample {
    public static void main(String[] args) {
        HelloAnnoExample example = new HelloAnnoExample();

        example.sayHi();
        example.sayHello();
    }

    @HelloAnno(value = "Hi there", greetTo = "Alice")
    public void sayHi() {
    }

    @HelloAnno(value = "Hello there", greetTo = "Bob")
    public void sayHello() {
    }
}

Wayan Saryada

Programmer, runner, recreational diver, live in the island of Bali, Indonesia 🇮🇩. Mostly programming in Java, creating web based application with Spring Framework, Hibernate / JPA.

Leave a Reply