{{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:

Generate Insert Sql from Select Statement

SELECT 'INSERT INTO ReferenceTable (ID, Name) VALUES (' +        CAST(ID AS NVARCHAR) + ', ''' + Name + ''...