What are the different types of annotations you can use in Java?

Brad Jones (jGuru)

There are a number of annotations built in to the java 5.0 API.

Within java.lang.annotations, there are a number of annotations that can be used when working with annotations ("annotation to annotate annotations"). The following are four such annotations in this package:

@Documented - Let's you specify whether documentation should be created for the given annotation.
@Inherited - Allows for subclasses of an annotated class to inherit the annotation as well.
@Retention - Defines how long the annotation should be retained.
@Target - Allows you to specify one or more program elements to apply the annotation to.

Defined in java.lang area few more annotations including the following:

@Deprecated - used to mark things as deprecated.
@Override - lets you use the compiler to confirm you are truly overriding something.
@SuppressWarnings - used to suppress compiler warnings.

It is also possible to create your own annotation types; however, this is something the typical application developer shouldn't need to do.

# # #

Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

About | Sitemap | Contact