{{theTime}}

Search This Blog

Total Pageviews

Java Reflection Example to Find Methods in a Class.

import static java.lang.System.err;

import java.lang.reflect.Method; 

public class FindPublicMethodsInAClass
{

    public static void main(String ...vars) {

       if (vars.length <= 0) {
            err.format("Enter Class name") ;
            return ;
        }       
        try{
            Class<?> inputclass = Class.forName(vars[0]) ;
            Object obj = inputclass.newInstance() ;         
            Method[] methods = ((Class<?>) obj).getDeclaredMethods() ;
            for ( Method method : methods) {
                System.out.println("Method Name: " + method.getName());
            }
        }catch(ClassNotFoundException | InstantiationException | IllegalAccessException e) {
            e.printStackTrace();
        }
    }
}

No comments:

Java Virtual Threads Java Virtual Threads Java Virtual Threads, introduced in Java 21 (JDK 18), are lightweight ...