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 android.text.TextUtils;
import java.lang.reflect.Field;

public class Main {
    public static void setField(String paramString, Object paramObject1, Object paramObject2) throws Exception {
        if (TextUtils.isEmpty(paramString))
            throw new RuntimeException("field name can not be empty");
        if (paramObject1 == null)
            throw new RuntimeException("target object can not be null");
        Field localField = paramObject1.getClass().getDeclaredField(paramString);
        if (localField == null)
            throw new RuntimeException("target object: " + paramObject1.getClass().getName()
                    + " do not have this field: " + paramString);
        localField.setAccessible(true);
        localField.set(paramObject1, paramObject2);
    }
}