271 return getDeclaringClass().getName().hashCode() ^ getName().hashCode(); 272 } 273 274 /** 275 * Returns a string describing this {@code Field}. The format is 276 * the access modifiers for the field, if any, followed 277 * by the field type, followed by a space, followed by 278 * the fully-qualified name of the class declaring the field, 279 * followed by a period, followed by the name of the field. 280 * For example: 281 * <pre> 282 * public static final int java.lang.Thread.MIN_PRIORITY 283 * private int java.io.FileDescriptor.fd 284 * </pre> 285 * 286 * <p>The modifiers are placed in canonical order as specified by 287 * "The Java Language Specification". This is {@code public}, 288 * {@code protected} or {@code private} first, and then other 289 * modifiers in the following order: {@code static}, {@code final}, 290 * {@code transient}, {@code volatile}. 291 */ 292 public String toString() { 293 int mod = getModifiers(); 294 return (((mod == 0) ? "" : (Modifier.toString(mod) + " ")) 295 + getTypeName(getType()) + " " 296 + getTypeName(getDeclaringClass()) + "." 297 + getName()); 298 } 299 300 /** 301 * Returns a string describing this {@code Field}, including 302 * its generic type. The format is the access modifiers for the 303 * field, if any, followed by the generic field type, followed by 304 * a space, followed by the fully-qualified name of the class 305 * declaring the field, followed by a period, followed by the name 306 * of the field. 307 * 308 * <p>The modifiers are placed in canonical order as specified by 309 * "The Java Language Specification". This is {@code public}, 310 * {@code protected} or {@code private} first, and then other 311 * modifiers in the following order: {@code static}, {@code final}, 312 * {@code transient}, {@code volatile}. 313 * 314 * @return a string describing this {@code Field}, including 315 * its generic type 316 * 317 * @since 1.5 318 */ 319 public String toGenericString() { 320 int mod = getModifiers(); 321 Type fieldType = getGenericType(); 322 return (((mod == 0) ? "" : (Modifier.toString(mod) + " ")) 323 + ((fieldType instanceof Class) ? 324 getTypeName((Class)fieldType): fieldType.toString())+ " " 325 + getTypeName(getDeclaringClass()) + "." 326 + getName()); 327 } 328 329 /** 330 * Returns the value of the field represented by this {@code Field}, on 331 * the specified object. The value is automatically wrapped in an 332 * object if it has a primitive type. 333 * 334 * <p>The underlying field's value is obtained as follows: 335 * 336 * <p>If the underlying field is a static field, the {@code obj} argument 337 * is ignored; it may be null. | 271 return getDeclaringClass().getName().hashCode() ^ getName().hashCode(); 272 } 273 274 /** 275 * Returns a string describing this {@code Field}. The format is 276 * the access modifiers for the field, if any, followed 277 * by the field type, followed by a space, followed by 278 * the fully-qualified name of the class declaring the field, 279 * followed by a period, followed by the name of the field. 280 * For example: 281 * <pre> 282 * public static final int java.lang.Thread.MIN_PRIORITY 283 * private int java.io.FileDescriptor.fd 284 * </pre> 285 * 286 * <p>The modifiers are placed in canonical order as specified by 287 * "The Java Language Specification". This is {@code public}, 288 * {@code protected} or {@code private} first, and then other 289 * modifiers in the following order: {@code static}, {@code final}, 290 * {@code transient}, {@code volatile}. 291 * 292 * @return a string describing this {@code Field} 293 * @jls 8.3.1 Field Modifiers 294 */ 295 public String toString() { 296 int mod = getModifiers(); 297 return (((mod == 0) ? "" : (Modifier.toString(mod) + " ")) 298 + getTypeName(getType()) + " " 299 + getTypeName(getDeclaringClass()) + "." 300 + getName()); 301 } 302 303 /** 304 * Returns a string describing this {@code Field}, including 305 * its generic type. The format is the access modifiers for the 306 * field, if any, followed by the generic field type, followed by 307 * a space, followed by the fully-qualified name of the class 308 * declaring the field, followed by a period, followed by the name 309 * of the field. 310 * 311 * <p>The modifiers are placed in canonical order as specified by 312 * "The Java Language Specification". This is {@code public}, 313 * {@code protected} or {@code private} first, and then other 314 * modifiers in the following order: {@code static}, {@code final}, 315 * {@code transient}, {@code volatile}. 316 * 317 * @return a string describing this {@code Field}, including 318 * its generic type 319 * 320 * @since 1.5 321 * @jls 8.3.1 Field Modifiers 322 */ 323 public String toGenericString() { 324 int mod = getModifiers(); 325 Type fieldType = getGenericType(); 326 return (((mod == 0) ? "" : (Modifier.toString(mod) + " ")) 327 + ((fieldType instanceof Class) ? 328 getTypeName((Class)fieldType): fieldType.toString())+ " " 329 + getTypeName(getDeclaringClass()) + "." 330 + getName()); 331 } 332 333 /** 334 * Returns the value of the field represented by this {@code Field}, on 335 * the specified object. The value is automatically wrapped in an 336 * object if it has a primitive type. 337 * 338 * <p>The underlying field's value is obtained as follows: 339 * 340 * <p>If the underlying field is a static field, the {@code obj} argument 341 * is ignored; it may be null. |