Package java.lang.reflect


Package java.lang.reflect

Java 1.1

The java.lang.reflect package contains the classes and interfaces that, along with java.lang.Class , comprise the Java Reflection API.

The Constructor , Field , and Method classes represent the constructors, fields, and methods of a class. Because these types all represent members of a class, they each implement the Member interface, which defines a simple set of methods that can be invoked for any class member. These classes allow information about the class members to be obtained, methods and constructors to be invoked, and fields to be queried and set.

Class member modifiers are represented as integers that specify a number of bit flags. The Modifier class defines static methods that help interpret the meanings of these flags. The Array class defines static methods for creating arrays and reading and writing array elements.

As of Java 1.3, the Proxy class allows the dynamic creation of new Java classes that implement a specified set of interfaces. When an interface method is invoked on an instance of such a proxy class, the invocation is delegated to an InvocationHandler object.

There have been a number of changes to this package to support the new language features of Java 5.0. The most important changes are support for querying the generic signature of classes, methods, constructors, and fields. Class , Method and Constructor implement the new GenericDeclaration interface, which provides access to the TypeVariable declarations of generic classes, methods, and constructors. In general, the package has been modified to add new generic versions of methods like Field.getType( ) and Method.getParameterTypes( ) . Instead of returning Class objects, the new generic methods, like Field.getGenericType( ) and Method.getGenericParameterTypes( ) , return Type objects. The Type interface is new in Java 5.0, and represents any kind of generic or nongeneric type. Class implements Type , so a Type object may simply be an ordinary Class . Type is also the super-interface for four other new interfaces: ParameterizedType , TypeVariable , WildcardType and GenericArrayType . A Type object that is not a Class should be an instance of one of these other interfaces, representing a generic type of some sort .

Support for reflection on annotations is provided by the AnnotatedElement interface which is implemented by Class , Package , Method , Constructor and Field . Method and Constructor also have new getParameterAnnotations( ) for querying annotations on method parameters. Other, more minor changes in Java 5.0 include the isEnumConstant( ) method of Field and the isVarArgs( ) method of Method and Constructor .

Interfaces

 public interface  AnnotatedElement  ; public interface  GenericArrayType  extends Type; public interface  GenericDeclaration  ; public interface  InvocationHandler  ; public interface  Member  ; public interface  ParameterizedType  extends Type; public interface  Type  ; public interface  TypeVariable  <D extends GenericDeclaration> extends Type; public interface  WildcardType  extends Type; 

Classes

 public class  AccessibleObject  implements AnnotatedElement;    public final class  Constructor  <T> extends AccessibleObject implements  GenericDeclaration, Member;    public final class  Field  extends AccessibleObject implements Member;    public final class  Method  extends AccessibleObject implements  GenericDeclaration, Member; public final class  Array  ; public class  Modifier  ; public class  Proxy  implements Serializable; public final class  ReflectPermission  extends java.security.BasicPermission; 

Exceptions

 public class  InvocationTargetException  extends Exception; public class  MalformedParameterizedTypeException  extends RuntimeException; public class  UndeclaredThrowableException  extends RuntimeException; 

Errors

 public class  GenericSignatureFormatError  extends ClassFormatError; 



Java In A Nutshell
Java In A Nutshell, 5th Edition
ISBN: 0596007736
EAN: 2147483647
Year: 2004
Pages: 1220

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net