Reflection allows the executing Java program to examine or introspect itself and manipulate internal properties of the program.
For example,
import java.lang.reflect.*;
class array1 {
public static void main(String args[]) {
try {
Class cls = Class.forName("java.lang.String");
Object arr = Array.newInstance(cls, 10);
Array.set(arr, 5, "this is a test");
String s = (String)Array.get(arr, 5);
System.out.println(s);
}
catch (Throwable e) {
System.err.println(e);
}
}
}
Practice Java code at https://github.com/j143/java-reflection-examples
https://www.oracle.com/technical-resources/articles/java/javareflection.html
Potential of Java in the coming years:
Cloud Adoption
Technology adoption
Top comments (0)