Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import java.lang.reflect.Field;

public class Main {
    public static Class<?> getClassByPropertyName(Class<?> clazz, String propertyName) {
        for (Field field : clazz.getDeclaredFields()) {
            if (field.getName().equals(propertyName)) {
                return field.getType();
            }
        }
        Class<?> superClass = clazz.getSuperclass();
        if (!superClass.equals(Object.class)) {
            return getClassByPropertyName(superClass, propertyName);
        }
        return null;
    }
}