📄 field.java
字号:
* is inaccessible. * @exception IllegalArgumentException if the specified object is not an * instance of the class or interface declaring the underlying * field (or a subclass or implementor thereof), * or if an unwrapping conversion fails. * @exception NullPointerException if the specified object is null * and the field is an instance field. * @exception ExceptionInInitializerError if the initialization provoked * by this method fails. * @see Field#set */ public void setByte(Object obj, byte b) throws IllegalArgumentException, IllegalAccessException { getFieldAccessor(obj).setByte(obj, b); } /** * Sets the value of a field as a <code>char</code> on the specified object. * This method is equivalent to * <code>set(obj, cObj)</code>, * where <code>cObj</code> is a <code>Character</code> object and * <code>cObj.charValue() == c</code>. * * @param obj the object whose field should be modified * @param c the new value for the field of <code>obj</code> * being modified * * @exception IllegalAccessException if the underlying field * is inaccessible. * @exception IllegalArgumentException if the specified object is not an * instance of the class or interface declaring the underlying * field (or a subclass or implementor thereof), * or if an unwrapping conversion fails. * @exception NullPointerException if the specified object is null * and the field is an instance field. * @exception ExceptionInInitializerError if the initialization provoked * by this method fails. * @see Field#set */ public void setChar(Object obj, char c) throws IllegalArgumentException, IllegalAccessException { getFieldAccessor(obj).setChar(obj, c); } /** * Sets the value of a field as a <code>short</code> on the specified object. * This method is equivalent to * <code>set(obj, sObj)</code>, * where <code>sObj</code> is a <code>Short</code> object and * <code>sObj.shortValue() == s</code>. * * @param obj the object whose field should be modified * @param s the new value for the field of <code>obj</code> * being modified * * @exception IllegalAccessException if the underlying field * is inaccessible. * @exception IllegalArgumentException if the specified object is not an * instance of the class or interface declaring the underlying * field (or a subclass or implementor thereof), * or if an unwrapping conversion fails. * @exception NullPointerException if the specified object is null * and the field is an instance field. * @exception ExceptionInInitializerError if the initialization provoked * by this method fails. * @see Field#set */ public void setShort(Object obj, short s) throws IllegalArgumentException, IllegalAccessException { getFieldAccessor(obj).setShort(obj, s); } /** * Sets the value of a field as an <code>int</code> on the specified object. * This method is equivalent to * <code>set(obj, iObj)</code>, * where <code>iObj</code> is a <code>Integer</code> object and * <code>iObj.intValue() == i</code>. * * @param obj the object whose field should be modified * @param i the new value for the field of <code>obj</code> * being modified * * @exception IllegalAccessException if the underlying field * is inaccessible. * @exception IllegalArgumentException if the specified object is not an * instance of the class or interface declaring the underlying * field (or a subclass or implementor thereof), * or if an unwrapping conversion fails. * @exception NullPointerException if the specified object is null * and the field is an instance field. * @exception ExceptionInInitializerError if the initialization provoked * by this method fails. * @see Field#set */ public void setInt(Object obj, int i) throws IllegalArgumentException, IllegalAccessException { getFieldAccessor(obj).setInt(obj, i); } /** * Sets the value of a field as a <code>long</code> on the specified object. * This method is equivalent to * <code>set(obj, lObj)</code>, * where <code>lObj</code> is a <code>Long</code> object and * <code>lObj.longValue() == l</code>. * * @param obj the object whose field should be modified * @param l the new value for the field of <code>obj</code> * being modified * * @exception IllegalAccessException if the underlying field * is inaccessible. * @exception IllegalArgumentException if the specified object is not an * instance of the class or interface declaring the underlying * field (or a subclass or implementor thereof), * or if an unwrapping conversion fails. * @exception NullPointerException if the specified object is null * and the field is an instance field. * @exception ExceptionInInitializerError if the initialization provoked * by this method fails. * @see Field#set */ public void setLong(Object obj, long l) throws IllegalArgumentException, IllegalAccessException { getFieldAccessor(obj).setLong(obj, l); } /** * Sets the value of a field as a <code>float</code> on the specified object. * This method is equivalent to * <code>set(obj, fObj)</code>, * where <code>fObj</code> is a <code>Float</code> object and * <code>fObj.floatValue() == f</code>. * * @param obj the object whose field should be modified * @param f the new value for the field of <code>obj</code> * being modified * * @exception IllegalAccessException if the underlying field * is inaccessible. * @exception IllegalArgumentException if the specified object is not an * instance of the class or interface declaring the underlying * field (or a subclass or implementor thereof), * or if an unwrapping conversion fails. * @exception NullPointerException if the specified object is null * and the field is an instance field. * @exception ExceptionInInitializerError if the initialization provoked * by this method fails. * @see Field#set */ public void setFloat(Object obj, float f) throws IllegalArgumentException, IllegalAccessException { getFieldAccessor(obj).setFloat(obj, f); } /** * Sets the value of a field as a <code>double</code> on the specified object. * This method is equivalent to * <code>set(obj, dObj)</code>, * where <code>dObj</code> is a <code>Double</code> object and * <code>dObj.doubleValue() == d</code>. * * @param obj the object whose field should be modified * @param d the new value for the field of <code>obj</code> * being modified * * @exception IllegalAccessException if the underlying field * is inaccessible. * @exception IllegalArgumentException if the specified object is not an * instance of the class or interface declaring the underlying * field (or a subclass or implementor thereof), * or if an unwrapping conversion fails. * @exception NullPointerException if the specified object is null * and the field is an instance field. * @exception ExceptionInInitializerError if the initialization provoked * by this method fails. * @see Field#set */ public void setDouble(Object obj, double d) throws IllegalArgumentException, IllegalAccessException { getFieldAccessor(obj).setDouble(obj, d); } // Convenience routine which performs security checks private FieldAccessor getFieldAccessor(Object obj) throws IllegalAccessException { doSecurityCheck(obj); if (fieldAccessor == null) { acquireFieldAccessor(); } return fieldAccessor; } // NOTE that there is no synchronization used here. It is correct // (though not efficient) to generate more than one FieldAccessor // for a given Field. However, avoiding synchronization will // probably make the implementation more scalable. private void acquireFieldAccessor() { // First check to see if one has been created yet, and take it // if so FieldAccessor tmp = null; if (root != null) tmp = root.getFieldAccessor(); if (tmp != null) { fieldAccessor = tmp; return; } // Otherwise fabricate one and propagate it up to the root tmp = reflectionFactory.newFieldAccessor(this); setFieldAccessor(tmp); } // Returns FieldAccessor for this Field object, not looking up // the chain to the root private FieldAccessor getFieldAccessor() { return fieldAccessor; } // Sets the FieldAccessor for this Field object and // (recursively) its root private void setFieldAccessor(FieldAccessor accessor) { fieldAccessor = accessor; // Propagate up if (root != null) { root.setFieldAccessor(accessor); } } // NOTE: be very careful if you change the stack depth of this // routine. The depth of the "getCallerClass" call is hardwired so // that the compiler can have an easier time if this gets inlined. private void doSecurityCheck(Object obj) throws IllegalAccessException { if (!override) { if (!Reflection.quickCheckMemberAccess(clazz, modifiers)) { Class caller = Reflection.getCallerClass(4); Class targetClass = ((obj == null || !Modifier.isProtected(modifiers)) ? clazz : obj.getClass()); if (securityCheckCache != caller || targetClass != securityCheckTargetClassCache) { Reflection.ensureMemberAccess(caller, clazz, obj, modifiers); securityCheckCache = caller; securityCheckTargetClassCache = targetClass; } } } } /* * Utility routine to paper over array type names */ static String getTypeName(Class type) { if (type.isArray()) { try { Class cl = type; int dimensions = 0; while (cl.isArray()) { dimensions++; cl = cl.getComponentType(); } StringBuffer sb = new StringBuffer(); sb.append(cl.getName()); for (int i = 0; i < dimensions; i++) { sb.append("[]"); } return sb.toString(); } catch (Throwable e) { /*FALLTHRU*/ } } return type.getName(); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -