-
Bug
-
Resolution: Fixed
-
P4
-
16
-
b26
For a Class to be considered a record class at runtime, Class::isRecord requires that the direct superclass is j.l.Record. While previewing, the implementation did this check reflectively, to avoid a static dependency on a previewing API. Now that records are final, the implementation can simply refer to j.l.Record statically.
--- a/src/java.base/share/classes/java/lang/Class.java
+++ b/src/java.base/share/classes/java/lang/Class.java
@@ -3661,16 +3661,6 @@ public final class Class<T> implements java.io.Serializable,
this.getSuperclass() == java.lang.Enum.class;
}
- /** java.lang.Record.class */
- private static final Class<?> JAVA_LANG_RECORD_CLASS = javaLangRecordClass();
- private static Class<?> javaLangRecordClass() {
- try {
- return Class.forName0("java.lang.Record", false, null, null);
- } catch (ClassNotFoundException e) {
- throw new InternalError("should not reach here", e);
- }
- }
-
/**
* Returns {@code true} if and only if this class is a record class.
*
@@ -3687,7 +3677,7 @@ public final class Class<T> implements java.io.Serializable,
* @since 16
*/
public boolean isRecord() {
- return getSuperclass() == JAVA_LANG_RECORD_CLASS && isRecord0();
+ return getSuperclass() == java.lang.Record.class && isRecord0();
}
--- a/src/java.base/share/classes/java/lang/Class.java
+++ b/src/java.base/share/classes/java/lang/Class.java
@@ -3661,16 +3661,6 @@ public final class Class<T> implements java.io.Serializable,
this.getSuperclass() == java.lang.Enum.class;
}
- /** java.lang.Record.class */
- private static final Class<?> JAVA_LANG_RECORD_CLASS = javaLangRecordClass();
- private static Class<?> javaLangRecordClass() {
- try {
- return Class.forName0("java.lang.Record", false, null, null);
- } catch (ClassNotFoundException e) {
- throw new InternalError("should not reach here", e);
- }
- }
-
/**
* Returns {@code true} if and only if this class is a record class.
*
@@ -3687,7 +3677,7 @@ public final class Class<T> implements java.io.Serializable,
* @since 16
*/
public boolean isRecord() {
- return getSuperclass() == JAVA_LANG_RECORD_CLASS && isRecord0();
+ return getSuperclass() == java.lang.Record.class && isRecord0();
}