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 Object invokeField(Class<?> cls, Object object, String fieldName) throws Exception {
        Field field = cls.getDeclaredField(fieldName);

        boolean accessible = field.isAccessible();
        try {
            field.setAccessible(true);
            return field.get(object);
        } finally {
            field.setAccessible(accessible);
        }
    }
}