diff --git a/src/java.base/share/classes/java/lang/Class.java b/src/java.base/share/classes/java/lang/Class.java index 2c57cde97a9..3031823045f 100644 --- a/src/java.base/share/classes/java/lang/Class.java +++ b/src/java.base/share/classes/java/lang/Class.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1994, 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1994, 2023, 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 @@ -126,20 +126,19 @@ import sun.reflect.misc.ReflectUtil; *

The following example uses a {@code Class} object to print the * class name of an object: * - *

- *     void printClassName(Object obj) {
- *         System.out.println("The class of " + obj +
- *                            " is " + obj.getClass().getName());
- *     }
- * 
+ * {@snippet lang="java" : + * void printClassName(Object obj) { + * System.out.println("The class of " + obj + + * " is " + obj.getClass().getName()); + * }} * * It is also possible to get the {@code Class} object for a named * class or interface (or for {@code void}) using a class literal. * For example: * - *
- * {@code System.out.println("The name of class Foo is: "+Foo.class.getName());} - *
+ * {@snippet lang="java" : + * System.out.println("The name of class Foo is: "+Foo.class.getName()); + * } * *

Some methods of class {@code Class} expose whether the declaration of * a class or interface in Java source code was enclosed within @@ -341,9 +340,9 @@ public final class Class implements java.io.Serializable, * interface with the given string name. Invoking this method is * equivalent to: * - *

- * {@code Class.forName(className, true, currentLoader)} - *
+ * {@snippet lang="java" : + * Class.forName(className, true, currentLoader) + * } * * where {@code currentLoader} denotes the defining class loader of * the current class. @@ -352,9 +351,9 @@ public final class Class implements java.io.Serializable, * runtime {@code Class} descriptor for the class named * {@code java.lang.Thread}: * - *
- * {@code Class t = Class.forName("java.lang.Thread")} - *
+ * {@snippet lang="java" : + * Class t = Class.forName("java.lang.Thread"); + * } *

* A call to {@code forName("X")} causes the class named * {@code X} to be initialized. @@ -415,15 +414,15 @@ public final class Class implements java.io.Serializable, * *

For example, in an instance method the expression: * - *

- * {@code Class.forName("Foo")} - *
+ * {@snippet lang="java" : + * Class.forName("Foo") + * } * * is equivalent to: * - *
- * {@code Class.forName("Foo", true, this.getClass().getClassLoader())} - *
+ * {@snippet lang="java" : + * Class.forName("Foo", true, this.getClass().getClassLoader()) + * } * * Note that this method throws errors related to loading, linking * or initializing as specified in Sections {@jls 12.2}, {@jls @@ -607,15 +606,15 @@ public final class Class implements java.io.Serializable, * *

The call * - *

{@code
+     * {@snippet lang="java" :
      * clazz.newInstance()
-     * }
+ * } * * can be replaced by * - *
{@code
+     * {@snippet lang="java" :
      * clazz.getDeclaredConstructor().newInstance()
-     * }
+ * } * * The latter sequence of calls is inferred to be able to throw * the additional exception types {@link @@ -2485,7 +2484,7 @@ public final class Class implements java.io.Serializable, * @apiNote *

The following method can be used to find the record canonical constructor: * - *

{@code
+     * {@snippet lang="java" :
      * static  Constructor getCanonicalConstructor(Class cls)
      *     throws NoSuchMethodException {
      *   Class[] paramTypes =
@@ -2493,7 +2492,7 @@ public final class Class implements java.io.Serializable,
      *           .map(RecordComponent::getType)
      *           .toArray(Class[]::new);
      *   return cls.getDeclaredConstructor(paramTypes);
-     * }}
+ * }} * * @return An array of {@code RecordComponent} objects representing all the * record components of this record class, or {@code null} if this