Day 21 of 100 - Java: Reflection

j143

Janardhan Pulivarthi

Posted on January 29, 2022

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);
            System.out.println(s);
        }
        catch (Throwable e) {
            System.err.println(e);
        }
    }
}
Enter fullscreen mode Exit fullscreen mode

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

cloud adoption

Technology adoption

technology adoption

πŸ’– πŸ’ͺ πŸ™… 🚩
j143
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.

Related

Day 23 of 100DaysOfCode
javascript Day 23 of 100DaysOfCode

October 3, 2024

Day21 of 100DaysOfCode
javascript Day21 of 100DaysOfCode

August 22, 2024

Day22 of 100DaysOfCode
javascript Day22 of 100DaysOfCode

September 7, 2024

Day 2 of #100daysofMiva Coding Challenge
100daysofmiva Day 2 of #100daysofMiva Coding Challenge

August 22, 2024