Java Reflection Field Set setField(T object, Field field, ResourceBundle bundle)

Here you can find the source of setField(T object, Field field, ResourceBundle bundle)

Description

set Field

License

Open Source License

Declaration

private static <T> void setField(T object, Field field, ResourceBundle bundle) throws IllegalAccessException 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2007, 2013 EclipseSource and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:/*from  w  w w  .  j  a  va2s .  com*/
 *    EclipseSource - initial API and implementation
 ******************************************************************************/

import java.lang.reflect.*;

import java.util.MissingResourceException;
import java.util.ResourceBundle;

public class Main {
    private static <T> void setField(T object, Field field, ResourceBundle bundle) throws IllegalAccessException {
        try {
            String value = bundle.getString(field.getName());
            if (value != null) {
                field.setAccessible(true);
                field.set(object, value);
            }
        } catch (MissingResourceException mre) {
            field.setAccessible(true);
            field.set(object, "");
            throw mre;
        }
    }
}

Related

  1. setField(String field, Object value)
  2. setField(String fieldName, Object instance, Class instanceClass, Object value)
  3. setField(String fieldName, Object instance, Object value)
  4. setField(String name, Object target, Object value)
  5. setField(String name, Object target, Object value)
  6. setFieldAccessible(Class clazz, String... names)
  7. setFieldAccessible(Field field)
  8. setFieldBySomeMethod(List setMethods, Object object, Object value)
  9. setFieldContent(final Object obj, final String name, final Object value)