How do I annotate a class or method?

Category: java.lang.annotation, viewed: 2026 time(s).

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() {
    }
}
Click here to lend your support to: Kode Java Org and make a donation at www.pledgie.com !

 

Can't find what you are looking for? Join our FORUMS and ask some questions!
Download Hundreds of Complimentary Industry Resources

Get hundreds of popular Industry magazines, white papers, webinars, podcasts, and more; all available at no cost to you. With more than 600 complimentary offers, you'll find plenty of titles to suit your professional interests and needs. Click Here and Sign up today!

Sponsored Links

Our Friends

Statistics

Locations of visitors to this page
visitor stats