List of usage examples for java.lang Object getClass
@HotSpotIntrinsicCandidate public final native Class<?> getClass();
From source file:Main.java
public static void invokeSet(Object o, String fieldName, Object value) { Method method = getSetMethod(o.getClass(), fieldName); try {//from ww w. ja v a 2 s . c o m method.invoke(o, new Object[] { value }); } catch (Exception e) { e.printStackTrace(); } }
From source file:Main.java
public static Object getField(Object obj, String fieldName) throws NoSuchFieldException, IllegalAccessException { return prepareField(obj.getClass(), fieldName).get(obj); }
From source file:Main.java
public static void setActionBarDrawable(Activity activity, Drawable drawable) { try {/*from w ww. j a va 2 s . c o m*/ Object actionBar = Activity.class.getMethod(METHOD_GETACTIONBAR).invoke(activity); actionBar.getClass().getMethod(METHOD_SETICON, Drawable.class).invoke(actionBar, drawable); } catch (Exception e) { } }
From source file:Main.java
public static void marshal(Object model, OutputStream output) throws JAXBException { JAXBContext jaxbContext = JAXBContext.newInstance(model.getClass()); Marshaller jaxbMarshaller = jaxbContext.createMarshaller(); jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); jaxbMarshaller.setProperty(Marshaller.JAXB_ENCODING, "UTF-8"); jaxbMarshaller.marshal(model, output); }
From source file:Main.java
public static Method getPrivateMethod(Object target, String methodName, Class<?>... parameterTypes) throws NoSuchMethodException { Class targetClass = target.getClass(); Method method = targetClass.getDeclaredMethod(methodName, parameterTypes); method.setAccessible(true);/*from w ww.java2s. c o m*/ return method; }
From source file:Main.java
public static int getIntField(Object obj, String fieldName) { try {/* w w w. j ava2s .c om*/ return findField(obj.getClass(), fieldName).getInt(obj); } catch (IllegalAccessException e) { // should not happen //XposedBridge.log(e); Log.v("test", e.getMessage()); throw new IllegalAccessError(e.getMessage()); } catch (IllegalArgumentException e) { throw e; } }
From source file:nz.co.senanque.logging.HashIdLogger.java
public static void log(Object object, Object id) { if (logger.isDebugEnabled()) { logger.debug("{}@{} {}", object.getClass(), System.identityHashCode(object), id); }/*from w w w . jav a 2s . c o m*/ }
From source file:Main.java
public static Object setObjectFileValue(Object obj, Map<String, String> data) throws Exception { Class<?> cls = obj.getClass(); Field[] fields = cls.getDeclaredFields(); for (Field field : fields) { Class<?> clsType = field.getType(); String name = field.getName(); String strSet = "set" + name.substring(0, 1).toUpperCase() + name.substring(1, name.length()); Method methodSet = cls.getDeclaredMethod(strSet, clsType); if (data.containsKey(name)) { Object objValue = typeConversion(clsType, data.get(name)); methodSet.invoke(obj, objValue); }//from w ww . ja v a2s .c o m } return obj; }
From source file:Main.java
public static boolean isAllNullArray(Object array) { if (array == null) { throw new NullPointerException(); }/*from www. j a v a 2 s . c om*/ if (!array.getClass().isArray()) { throw new IllegalArgumentException("Expected array but received " + array.getClass()); } for (int i = 0; i < Array.getLength(array); i++) { if (Array.get(array, i) != null) { return false; } } return true; }
From source file:com.angstoverseer.util.ReflectionUtil.java
public static void setField(String fieldName, Object target, Object value) { final Field field = ReflectionUtils.findField(target.getClass(), fieldName); field.setAccessible(true);/*from w w w .ja v a 2 s. c o m*/ ReflectionUtils.setField(field, target, value); }