< prev index next > src/java.base/share/classes/java/lang/reflect/Field.java
Print this page
*/
package java.lang.reflect;
import jdk.internal.access.SharedSecrets;
+ import jdk.internal.value.PrimitiveClass;
import jdk.internal.reflect.CallerSensitive;
import jdk.internal.reflect.FieldAccessor;
import jdk.internal.reflect.Reflection;
import jdk.internal.vm.annotation.ForceInline;
import jdk.internal.vm.annotation.Stable;
boolean trustedFinal,
int slot,
String signature,
byte[] annotations)
{
+ assert PrimitiveClass.isPrimaryType(declaringClass);
this.clazz = declaringClass;
this.name = name;
this.type = type;
this.modifiers = modifiers;
this.trustedFinal = trustedFinal;
}
/**
* {@return an unmodifiable set of the {@linkplain AccessFlag
* access flags} for this field, possibly empty}
* @see #getModifiers()
* @jvms 4.5 Fields
* @since 20
*/
@Override
public Set<AccessFlag> accessFlags() {
! return AccessFlag.maskToAccessFlags(getModifiers(), AccessFlag.Location.FIELD);
}
/**
* Returns {@code true} if this field represents an element of
* an enumerated class; returns {@code false} otherwise.
}
/**
* {@return an unmodifiable set of the {@linkplain AccessFlag
* access flags} for this field, possibly empty}
+ * The {@code AccessFlags} may depend on the class file format version of the class.
+ *
* @see #getModifiers()
* @jvms 4.5 Fields
* @since 20
*/
@Override
public Set<AccessFlag> accessFlags() {
! int major = SharedSecrets.getJavaLangAccess().classFileFormatVersion(getDeclaringClass()) & 0xffff;
+ var cffv = ClassFileFormatVersion.fromMajor(major);
+ return AccessFlag.maskToAccessFlags(getModifiers(),
+ AccessFlag.Location.FIELD,
+ cffv);
}
/**
* Returns {@code true} if this field represents an element of
* an enumerated class; returns {@code false} otherwise.
*/
public String toString() {
int mod = getModifiers();
return (((mod == 0) ? "" : (Modifier.toString(mod) + " "))
+ getType().getTypeName() + " "
! + getDeclaringClass().getTypeName() + "."
+ getName());
}
@Override
String toShortString() {
! return "field " + getDeclaringClass().getTypeName() + "." + getName();
}
/**
* Returns a string describing this {@code Field}, including
* its generic type. The format is the access modifiers for the
*/
public String toString() {
int mod = getModifiers();
return (((mod == 0) ? "" : (Modifier.toString(mod) + " "))
+ getType().getTypeName() + " "
! + getDeclaringClassTypeName() + "."
+ getName());
}
@Override
String toShortString() {
! return "field " + getDeclaringClassTypeName() + "." + getName();
+ }
+
+ String getDeclaringClassTypeName() {
+ Class<?> c = getDeclaringClass();
+ if (PrimitiveClass.isPrimitiveClass(c)) {
+ c = PrimitiveClass.asValueType(c);
+ }
+ 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() + "."
+ getName());
}
/**
* Returns the value of the field represented by this {@code Field}, on
public String toGenericString() {
int mod = getModifiers();
Type fieldType = getGenericType();
return (((mod == 0) ? "" : (Modifier.toString(mod) + " "))
+ fieldType.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>
* <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}.
* <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};</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 >