Day 21 of 100 - Java: Reflection
Janardhan Pulivarthi
Posted on January 29, 2022
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
π πͺ π
π©
Janardhan Pulivarthi
Posted on January 29, 2022
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.