List of usage examples for java.lang.reflect Field set
@CallerSensitive @ForceInline public void set(Object obj, Object value) throws IllegalArgumentException, IllegalAccessException
From source file:Main.java
public static void setFieldValue(Object receiver, Field field, Object value) { if (field == null) { return;//w w w .j a va 2 s . c om } try { field.set(receiver, value); } catch (Exception e) { if (DEBUG) { e.printStackTrace(); } } }
From source file:com.basho.riak.client.api.convert.reflection.ClassUtil.java
public static void setFieldValue(Field field, Object obj, Object value) { try {/*from w w w . j a v a2s . c o m*/ field.set(obj, value); } catch (IllegalAccessException e) { throw new IllegalStateException("Unable to set Riak annotated field value", e); } }
From source file:Main.java
public static boolean setReflection(Object itemToGetObject, String objectName, Object newValue) { try {//w w w. j a v a 2 s .c om Class<?> clazz = itemToGetObject.getClass(); Field field; field = clazz.getDeclaredField(objectName); field.setAccessible(true); field.set(itemToGetObject, newValue); } catch (Exception e) { e.printStackTrace(); return false; } return true; }
From source file:Main.java
public static Object set(Field f, Object obj, Object value) throws IllegalArgumentException, IllegalAccessException { f.setAccessible(true);/*from w w w .ja va 2s . com*/ f.set(obj, value); return f.get(obj); }
From source file:Main.java
private static void setField(Object obj, Class<?> cl, String field, Object value) throws NoSuchFieldException, IllegalArgumentException, IllegalAccessException { Field localField = cl.getDeclaredField(field); localField.setAccessible(true);//from w ww.jav a 2 s . c om localField.set(obj, value); }
From source file:Main.java
/** * Resets MBeanServerFactory and ManagementFactory to a known consistent state. * This involves releasing all currently registered MBeanServers and resetting * the platformMBeanServer to null.// ww w .ja v a 2 s . c om */ public static void resetMBeanServers() throws Exception { for (MBeanServer server : MBeanServerFactory.findMBeanServer(null)) { MBeanServerFactory.releaseMBeanServer(server); } Field field = ManagementFactory.class.getDeclaredField("platformMBeanServer"); field.setAccessible(true); field.set(null, null); }
From source file:Main.java
private static void setDeclaredField(Object obj, String name, Object value) throws SecurityException, NoSuchFieldException, IllegalArgumentException, IllegalAccessException { Field f = obj.getClass().getDeclaredField(name); f.setAccessible(true);//ww w.ja va2s.c o m f.set(obj, value); }
From source file:Main.java
public static void setDialogPositiveButtonHolder(DialogInterface dialog, Boolean flag) { try {/*from w w w . j a v a2 s. c o m*/ Field field = dialog.getClass().getSuperclass().getDeclaredField("mShowing"); field.setAccessible(true); field.set(dialog, flag); } catch (Exception e) { e.printStackTrace(); } }
From source file:Main.java
protected static void replaceFont(String staticTypefaceFieldName, final Typeface newTypeface) { try {/* ww w . j a v a 2s. c om*/ final Field staticField = Typeface.class.getDeclaredField(staticTypefaceFieldName); staticField.setAccessible(true); staticField.set(null, newTypeface); } catch (NoSuchFieldException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } }
From source file:Main.java
public static void setFieldValue(final Object receiver, final Field field, final Object value) { if (field == null) { return;/*from w ww .jav a2 s.c o m*/ } try { field.set(receiver, value); } catch (final IllegalAccessException | IllegalArgumentException e) { Log.e(TAG, "Exception in setFieldValue", e); } }