print All Information about a class via reflection - Android java.lang.reflect

Android examples for java.lang.reflect:Class

Description

print All Information about a class via reflection

Demo Code


//package com.java2s;
import java.lang.reflect.Method;
import java.lang.reflect.Field;

import android.util.Log;

public class Main {

    static public void printAllInform(Class clsShow) {
        try {/*w  w  w  . j a va2s.c  om*/

            Method[] hideMethod = clsShow.getMethods();
            int i = 0;
            for (; i < hideMethod.length; i++) {
                Log.e("method name", hideMethod[i].getName()
                        + ";and the i is:" + i);
            }

            Field[] allFields = clsShow.getFields();
            for (i = 0; i < allFields.length; i++) {
                Log.e("Field name", allFields[i].getName());
            }
        } catch (SecurityException e) {
            // throw new RuntimeException(e.getMessage());
            e.printStackTrace();
        } catch (IllegalArgumentException e) {
            // throw new RuntimeException(e.getMessage());
            e.printStackTrace();
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
}

Related Tutorials