< prev index next > src/java.base/share/classes/java/lang/reflect/Field.java
Print this page
/*
- * Copyright (c) 1996, 2021, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1996, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
*/
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;
*/
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 (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() + "."
+ + 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 >