Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//License from project: Open Source License 

import java.lang.reflect.Field;

import java.util.HashMap;

import java.util.Map;

public class Main {

    @SuppressWarnings("rawtypes")
    private static Map<String, Class> getClassFields(Class clazz, boolean includeParentClass) {

        Map<String, Class> map = new HashMap<String, Class>();

        Field[] fields = clazz.getDeclaredFields();

        for (Field field : fields) {

            map.put(clazz.getName() + "." + field.getName(), field.getType());// field.getType()

        }

        if (includeParentClass)

            getParentClassFields(map, clazz.getSuperclass());

        return map;

    }

    @SuppressWarnings("rawtypes")
    private static Map<String, Class> getParentClassFields(Map<String, Class> map, Class clazz) {

        Field[] fields = clazz.getDeclaredFields();

        for (Field field : fields) {

            map.put(clazz.getName() + "." + field.getName(), field.getType());

        }

        if (clazz.getSuperclass() == null) {

            return map;

        }

        getParentClassFields(map, clazz.getSuperclass());

        return map;

    }
}