annotations : Java Glossary

Used in the form @interface or @Retention. These are annotations, a full-fledge feature of Java version 1.6 or later, though they were partly implemented in Java version 1.5 (supporting standard annotations without custom annotations). You can use them to add metadata to your programs useful to various utilities that process the text, e.g. for persistent object store implementations. They can also be used for inserting boiler plate in programs. You use them as you would the attribute static, declaring a class, variable or method to be marked with a given annotation.
The Basics Learning More
@SuppressWarnings Links

The Basics

These @annotations not Javadoc comment tags! They are part of the program proper.

@Retention(RetentionPolicy.RUNTIME) means the following annotation should be retained in the class files.

@Target(ElementType.METHOD) means the following annotation only applies to methods in the class, not the whole class.

@Documents means the following annotation should show up in the Javadoc.

Now that you have defined it, you can annotate any class with it, which embeds the copyright notice in the class file, with otherwise changing the class file. It does not add any methods or fields to your class, though it is sometimes possible to get at the information through the java.lang.annotation package methods. Here is how you use it:


In Java version 1.5, Sun introduced an annotation called @SuppressWarnings. Unfortunately, it is ignored prior to JDK (Java Development Kit) 1.5.0_06. You just insert the annotation prior to a class or method declaration telling which sort of warning you want suppressed. Further, you are not permitted to use them if you have -target 1.4 or earlier, not even @SuppressWarnings. You use them like this:

As well as classes and methods, @SuppressWarnings also applicable to enum, interface, constructor, field, parameter and local variable declarations.

Annotations do not inherit.

Here are the sorts of warning you can suppress:

@SuppressWarnings Options
Option Notes
all @SuppressWarnings( all ) means suppress all warnings
allDeprecation deprecation even inside deprecated code
allJavadoc invalid or missing Javadoc
assertIdentifier occurrence of assert used as identifier
boxing autoboxing conversion
cast cast operations
charConcat when a char array is used in a string concatenation without being converted explicitly to a string
conditionAssign possible accidental boolean assignment
constructorName method with constructor name
dep-ann missing @Deprecated annotation
deprecation usage of deprecated type or member outside deprecated code
emptyBlock undocumented empty block
enumSwitch incomplete enum switch
incomplete-switch incomplete switch
fallthrough Mark that fallthrough in switch cases was deliberate, not just a missing break.
fieldHiding field hiding another variable
finalBound type parameter with final bound
finally finally block not completing normally
hiding shorthand for fieldHiding, localHiding, typeHiding and maskedCatchBlock
indirectStatic indirect reference to static member
intfAnnotation annotation type used as super interface
intfNonInherited interface non-inherited method compatibility
Javadoc invalid Javadoc
localHiding local variable hiding another variable
maskedCatchBlocks hidden catch block
nls non-nls string literals
noEffectAssign for assignment with no effect
null missing or redundant null check
over-ann missing @Override annotation
pkgDefaultMethod attempt to override package-default method
rawtypes un-specific types when using generics on class params
restriction usage of discouraged or forbidden references
serial missing serialVersionUID
semicolon unnecessary semicolon or empty statement
specialParamHiding constructor or setter parameter hiding another field
static-access shorthand for indirectStatic and staticReceiver
staticReceiver if a non static receiver is used to get a static field or call a static method
suppress enable @SuppressWarnings
syntheticAccess when performing synthetic access for innerclass
synthetic-access when performing synthetic access for innerclass
tasks enable support for tasks tags in source code
typeHiding type parameter hiding another type
unchecked unchecked type operation
unnecessaryElse unnecessary else clause
unqualified-field-access unqualified reference to field
unqualifiedField unqualified reference to field
unused shorthand for unusedArgument, unusedImport, unusedLocal, unusedPrivate and unusedThrown
unusedArgument unused method argument
unusedImport unused import reference
unusedLocal unused local variable
unusedPrivate unused private member declaration
unusedThrown unused declared thrown exception
uselessTypeCheck unnecessary cast/instanceof operation
varargsCast varargs argument need explicit cast
warningToken unhandled warning token in @SuppressWarnings

Some of the options above are for Eclipse only, however Javac will quietly ignore them.


There is no override keyword to warn the compiler your method is intended to override a method in the base class. However, since Java version 1.5 or later, there is an @Override annotation. @Override serves as documentation for the reader and a double check in the compiler. The compiler will warn you if your method is not overriding properly, usually because the two method names are not spelled exactly the same way. Note it is @Overridewith capital O and double r, not @overide. Don’t confuse the @Override annotation with the unofficial @override Javadoc command. Here is how you would use the @Override annotation to indicate that a method is overriding another in the base class. Note it is not inside the Javadoc comment!

 * Get String presentation for this Thing object.
 * @return human readable summary of fields in Thing object.
public String toString()
   return desc + " " + quantity + " " + losses;

Learning More

Oracle’s Technote Guide on annotations : available:
Oracle’s Javadoc on Class.isAnnotationPresent : available:

available on the web at:
ClustrMaps is down

optional Replicator mirror
on local hard disk J:

Please the feedback from other visitors, or your own feedback about the site.
Contact Roedy.
Your face IP:[]
You are visitor number 63,487.