View Source

h3.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

h5.Arrays

* [array2.java|http://java.sun.com/developer/technicalArticles/ALT/Reflection/index.html#8] 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|http://java.sun.com/developer/technicalArticles/ALT/Reflection/index.html].

h5.Examining Classes

* [constructor1.java|http://java.sun.com/developer/technicalArticles/ALT/Reflection/index.html#3] determines which constructors are defined in a given class. For supporting information see [Using Java Reflection|http://java.sun.com/developer/technicalArticles/ALT/Reflection/index.html].

* [find1.java|http://java.sun.com/developer/technicalArticles/ALT/Reflection/index.html#4] determines which data fields are defined in a given class. For supporting information see [Using Java Reflection|http://java.sun.com/developer/technicalArticles/ALT/Reflection/index.html].

* [instance1.java|http://java.sun.com/developer/technicalArticles/ALT/Reflection/index.html#1] checks to see which objects are instances of a given class. For supporting information see [Using Java Reflection|http://java.sun.com/developer/technicalArticles/ALT/Reflection/index.html].

* [method1.java|http://java.sun.com/developer/technicalArticles/ALT/Reflection/index.html#2] determines which methods are defined in a given class. For supporting information see [Using Java Reflection|http://java.sun.com/developer/technicalArticles/ALT/Reflection/index.html].

h5.Manipulating Objects

* [field2.java|http://java.sun.com/developer/technicalArticles/ALT/Reflection/index.html#7] changes the value of data fields in objects. For supporting information see [Using Java Reflection|http://java.sun.com/developer/technicalArticles/ALT/Reflection/index.html].

* [Method interposing example|http://java.sun.com/developer/technicalArticles/JavaLP/Interposing/#code1] shows how to use the common interface provided by the Proxy class to encode and dispatch a method invocation to another object.

* [method2.java|http://java.sun.com/developer/technicalArticles/ALT/Reflection/index.html#5] invokes a specific method by its name. For supporting information see [Using Java Reflection|http://java.sun.com/developer/technicalArticles/ALT/Reflection/index.html].

* [constructor2.java|http://java.sun.com/developer/technicalArticles/ALT/Reflection/index.html#6] 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|http://java.sun.com/developer/technicalArticles/ALT/Reflection/index.html].

----

^1^ As used on this web site, the terms Java virtual machine or JVM mean a virtual machine for the Java platform.

----

The individuals who post here are part of the extended Sun Microsystems community and they might not be employed or in any way formally affiliated with Sun Microsystems. The opinions expressed here are their own, are not necessarily reviewed in advance by anyone but the individual authors, and neither Sun nor any other party necessarily agrees with them.

Copyright 1994-2009 Sun Microsystems, Inc.
Powered by Atlassian Confluence
Sun Guidelines on Public Discourse Privacy Policy Terms of Use Trademarks Site Map Employment Investor Relations Contact