Reflection API Code Samples
The Reflection API represents or reflects the classes, interfaces, and objects in the Java virtual machine. (JVM 1).
- Arrays
- Examining Classes
- Manipulating Objects
Arrays
- array2.java creates a 10-long array of Strings and sets location 5 in the array to a string value. The value is retrieved and displayed. For supporting information see Using Java Reflection.
Examining Classes
- constructor1.java determines which constructors are defined in a given class. For supporting information see Using Java Reflection.
- find1.java determines which data fields are defined in a given class. For supporting information see Using Java Reflection.
- instance1.java checks to see which objects are instances of a given class. For supporting information see Using Java Reflection.
- method1.java determines which methods are defined in a given class. For supporting information see Using Java Reflection.
Manipulating Objects
- field2.java changes the value of data fields in objects. For supporting information see Using Java Reflection.
- Method interposing example shows how to use the common interface provided by the Proxy class to encode and dispatch a method invocation to another object.
- method2.java invokes a specific method by its name. For supporting information see Using Java Reflection.
- constructor2.java finds a constructor that handles the specified parameter types and invokes it to create a new instance of the object. For supporting information see Using Java Reflection.
1 As used on this web site, the terms Java virtual machine or JVM mean a virtual machine for the Java platform.