< prev index next > src/java.base/share/classes/java/lang/reflect/Field.java
Print this page
boolean trustedFinal,
int slot,
String signature,
byte[] annotations)
{
+ assert declaringClass.isPrimaryType();
this.clazz = declaringClass;
this.name = name;
this.type = type;
this.modifiers = modifiers;
this.trustedFinal = trustedFinal;
*/
public String toString() {
int mod = getModifiers();
return (((mod == 0) ? "" : (Modifier.toString(mod) + " "))
+ getType().getTypeName() + " "
- + getDeclaringClass().getTypeName() + "."
+ + getDeclaringClassTypeName() + "."
+ getName());
}
@Override
String toShortString() {
- return "field " + getDeclaringClass().getTypeName() + "." + getName();
+ return "field " + getDeclaringClassTypeName() + "." + getName();
+ }
+
+ String getDeclaringClassTypeName() {
+ Class<?> c = getDeclaringClass();
+ if (c.isPrimitiveClass()) {
+ c = c.asValueType();
+ }
+ return c.getTypeName();
}
/**
* Returns a string describing this {@code Field}, including
* its generic type. The format is the access modifiers for the
public String toGenericString() {
int mod = getModifiers();
Type fieldType = getGenericType();
return (((mod == 0) ? "" : (Modifier.toString(mod) + " "))
+ fieldType.getTypeName() + " "
- + getDeclaringClass().getTypeName() + "."
+ + getDeclaringClassTypeName() + "."
+ getName());
}
/**
* Returns the value of the field represented by this {@code Field}, on
* <ul>
* <li>{@link #setAccessible(boolean) setAccessible(true)} has succeeded for
* this {@code Field} object;</li>
* <li>the field is non-static; and</li>
* <li>the field's declaring class is not a {@linkplain Class#isHidden()
- * hidden class}; and</li>
+ * hidden class};</li>
+ * <li>the field's declaring class is not a {@linkplain Class#isValue()
+ * value class}; and</li>
* <li>the field's declaring class is not a {@linkplain Class#isRecord()
* record class}.</li>
* </ul>
* If any of the above checks is not met, this method throws an
* {@code IllegalAccessException}.
< prev index next >