Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//License from project: Apache License 

import java.lang.reflect.Field;

public class Main {
    public static void setFieldValue(Object object, Field field, Object value) {
        try {
            setAccessibleIfNeeded(field);
            field.set(object, value);
        } catch (final Exception e) {
            throw new RuntimeException(e);
        }
    }

    public static void setAccessibleIfNeeded(Field field) {
        if (!field.isAccessible()) {
            field.setAccessible(true);
        }
    }
}