DEV Community

Janardhan Pulivarthi
Janardhan Pulivarthi

Posted on

Day 21 of 100 - Java: Reflection

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);
        catch (Throwable e) {
Enter fullscreen mode Exit fullscreen mode

Practice Java code at

Potential of Java in the coming years:

Cloud Adoption

cloud adoption

Technology adoption

technology adoption

Top comments (0)