Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
import java.lang.reflect.Field;
import java.lang.reflect.Method;

import java.util.Locale;

public class Main {
    /**
     * @param type
     * @param object
     * @param field
     * @param value
     */
    public static <T> void setFieldValue(Class<? extends T> type, T object, Field field, Object value) {
        try {
            Method m = type.getMethod("set" + getFirstLetterUppercased(field.getName()), field.getType());
            m.invoke(object, value);
        } catch (Exception e) {
        }
    }

    /**
     * @param s
     * @return
     */
    public static String getFirstLetterUppercased(String s) {
        StringBuilder sb = new StringBuilder(s.substring(0, 1).toUpperCase(Locale.getDefault()));
        sb.append(s.substring(1));
        return sb.toString();
    }
}