When an annotation type that has an
@Inherited
meta-annotation is applied to a class, that annotation should be inherited by subclasses and descendants of the annotated class. The inheritance is only for classes and their subclasses. If an
@Inherited
annotation type is applied to a method or program element other than a class, no inheritance applies. If the
@Inherited
annotation type also has runtime
Retention
, reflective access to the annotation through
java.lang.reflect.AnnotatedElement
Figure 10-79. java.lang.annotation.Inherited
public @interface
Inherited
{
}
|
A meta-annotation of this type specifies how long the annotated annotation type should be retained. The value( ) of this annotation type is one of the three RetentionPolicy enumerated constants. See RetentionPolicy for details. If an annotation type does not have an @Retention meta-annotation, its default retention is RetentionPolicy.CLASS . Figure 10-80. java.lang.annotation.Retentionpublic @interface Retention { // Public Instance Methods RetentionPolicy value ( ); } |
The constants declared by the enumerated type specify the possible retention values for an @Retention meta-annotation. Annotations with SOURCE retention appear in Java source code only and are discarded by the compiler. Annotations with CLASS retention are compiled into the class file and are visible to tools that read class files but are not loaded by the Java VM at runtime. (This is the default retention for annotation types that do not have an @Retention meta-annotation.) Finally, annotations with RUNTIME retention are stored in the class file and loaded by the Java interpreter at runtime. These annotations are available for reflective access through java.lang.reflect.AnnotatedElement . Figure 10-81. java.lang.annotation.RetentionPolicypublic enum RetentionPolicy { // Enumerated Constants SOURCE , CLASS , RUNTIME ; // Public Class Methods public static RetentionPolicy valueOf (String name ); public static final RetentionPolicy[ ] values ( ); } Returned ByRetention.value( ) |
A meta-annotation of this type specifies what program elements the annotated annotation type can be applied to. The value( ) of a Target annotation is an array of ElementType enumerated constants. See ElementType for details on the allowed values. If an annotation type does not have an @Target meta-annotation, it can be applied to any program element. Figure 10-82. java.lang.annotation.Targetpublic @interface Target { // Public Instance Methods ElementType[ ] value ( ); } |
This package defines the API for instrumenting a Java VM by transforming class files to add profiling support, code coverage testing, or other features.
The
-javaagent
command-line option to the Java interpreter provides a hook for running the
premain( )
method of a Java instrumentation
agent
. An
Instrumentation
object passed to the
premain( )
method provides an entry point into this package, and
Interfacespublic interface ClassFileTransformer ; public interface Instrumentation ; Classes
public final class
ClassDefinition
;
Exceptionspublic class IllegalClassFormatException extends Exception; public class UnmodifiableClassException extends Exception; |