Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.HashMap;

public class Main {

    public static HashMap<String, Object> testReflect(Object obj)
            throws IllegalArgumentException, IllegalAccessException, InvocationTargetException {
        HashMap<String, Object> hashMap = new HashMap<String, Object>();
        Class c = obj.getClass();
        Method m[] = c.getDeclaredMethods();
        for (int i = 0; i < m.length; i++) {
            if (m[i].getName().indexOf("get") == 0) {
                hashMap.put(m[i].getName(), m[i].invoke(obj, new Object[0]));
            }
        }
        return hashMap;
    }
}