Package java.lang.reflect
Classes in this package, along withjava.lang.Class
accommodate applications such as debuggers, interpreters, object inspectors, class browsers, and services such as Object Serialization and JavaBeans that need access to either the public members of a target object (based on its runtime class) or the members declared by a given class.
Array
provides static methods to dynamically create and access arrays.
Java programming language and JVM modeling in core reflection
The components of core reflection, which include types in this package as well asClass
,Package
, andModule
, fundamentally present a JVM model of the entities in question rather than a Java programming language model. A Java compiler, such asjavac
, translates Java source code into executable output that can be run on a JVM, primarilyclass
files. Compilers for source languages other than Java can and do target the JVM as well.The translation process, including from Java language sources, to executable output for the JVM is not a one-to-one mapping. Structures present in the source language may have no representation in the output and structuresnot present in the source language may be present in the output. The latter are calledsynthetic structures. Synthetic structures can includemethods,fields,parameters,classes and interfaces. One particular kind of synthetic method is abridge method. It is possible a synthetic structure may not be marked as such. In particular, not allclass
file versions support marking a parameter as synthetic. A source language compiler generally has multiple ways to translate a source program into aclass
file representation. The translation may also depend on the version of theclass
file format being targeted as different class
file versions have different capabilities and features. In some cases the modifiers present in theclass
file representation may differ from the modifiers on the originating element in the source language, includingfinal
on aparameter andprotected
,private
, andstatic
onclasses and interfaces.
Besides differences in structural representation between the source language and the JVM representation, core reflection also exposes runtime specific information. For example, theclass loaders andprotection domains of aClass
are runtime concepts without a direct analogue in source code.
- SeeJava Language Specification:
- 13.1 The Form of a Binary
- SeeJava Virtual Machine Specification:
- 1.2 The Java Virtual Machine
4.7.8 The Synthetic Attribute
5.3.1 Loading Using the Bootstrap Class Loader
5.3.2 Loading Using a User-defined Class Loader - Since:
- 1.1
- Related PackagesPackageDescriptionProvides classes that are fundamental to the design of the Java programming language.
- ClassDescriptionA location within a class file where flags can be applied.The
AccessibleObject
class is the base class forField
,Method
, andConstructor
objects (known asreflected objects).AnnotatedArrayType
represents the potentially annotated use of an array type, whose component type may itself represent the annotated use of a type.Represents an annotated construct of the program currently running in this VM.AnnotatedParameterizedType
represents the potentially annotated use of a parameterized type, whose type arguments may themselves represent annotated uses of types.AnnotatedType
represents the potentially annotated use of a type in the program currently running in this VM.AnnotatedTypeVariable
represents the potentially annotated use of a type variable, whose declaration may have bounds which themselves represent annotated uses of types.AnnotatedWildcardType
represents the potentially annotated use of a wildcard type argument, whose upper or lower bounds may themselves represent annotated uses of types.TheArray
class provides static methods to dynamically create and access Java arrays.Class file format versions of the Java virtual machine.Constructor<T>Constructor
provides information about, and access to, a single constructor for a class.A shared superclass for the common functionality ofMethod
andConstructor
.AField
provides information about, and dynamic access to, a single field of a class or an interface.GenericArrayType
represents an array type whose component type is either a parameterized type or a type variable.A common interface for all entities that declare type variables.Thrown when a syntactically malformed signature attribute is encountered by a reflective method that needs to interpret the generic signature information for a class or interface, method or constructor.Thrown when Java language access checks cannot be suppressed.InvocationHandler
is the interface implemented by theinvocation handler of a proxy instance.InvocationTargetException is a checked exception that wraps an exception thrown by an invoked method or constructor.Thrown when a semantically malformed parameterized type is encountered by a reflective method that needs to instantiate it.Thrown whenthe java.lang.reflect package
attempts to read method parameters from a class file and determines that one or more parameters are malformed.Member is an interface that reflects identifying information about a single member (a field or a method) or a constructor.AMethod
provides information about, and access to, a single method on a class or interface.The Modifier class providesstatic
methods and constants to decode class and member access modifiers.Information about method parameters.ParameterizedType represents a parameterized type such asCollection<String>
.Proxy
provides static methods for creating objects that act like instances of interfaces but allow for customized method invocation.ARecordComponent
provides information about, and dynamic access to, a component of a record class.The Permission class for reflective operations.Type is the common superinterface for all types in the Java programming language.TypeVariable<D extendsGenericDeclaration>TypeVariable is the common superinterface for type variables of kinds.Thrown by a method invocation on a proxy instance if its invocation handler'sinvoke
method throws a checked exception (aThrowable
that is not assignable toRuntimeException
orError
) that is not assignable to any of the exception types declared in thethrows
clause of the method that was invoked on the proxy instance and dispatched to the invocation handler.WildcardType represents a wildcard type expression, such as?
,? extends Number
, or? super Integer
.