8308987: Update java.lang.Class to use javadoc snippets

Reviewed-by: alanb
This commit is contained in:
Joe Darcy 2023-05-30 16:47:02 +00:00
parent 04b0e785f6
commit 1b8e6bf31c

View File

@ -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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -126,20 +126,19 @@ import sun.reflect.misc.ReflectUtil;
* <p> The following example uses a {@code Class} object to print the * <p> The following example uses a {@code Class} object to print the
* class name of an object: * class name of an object:
* *
* <blockquote><pre> * {@snippet lang="java" :
* void printClassName(Object obj) { * void printClassName(Object obj) {
* System.out.println("The class of " + obj + * System.out.println("The class of " + obj +
* " is " + obj.getClass().getName()); * " is " + obj.getClass().getName());
* } * }}
* </pre></blockquote>
* *
* It is also possible to get the {@code Class} object for a named * It is also possible to get the {@code Class} object for a named
* class or interface (or for {@code void}) using a <i>class literal</i>. * class or interface (or for {@code void}) using a <i>class literal</i>.
* For example: * For example:
* *
* <blockquote> * {@snippet lang="java" :
* {@code System.out.println("The name of class Foo is: "+Foo.class.getName());} * System.out.println("The name of class Foo is: "+Foo.class.getName());
* </blockquote> * }
* *
* <p> Some methods of class {@code Class} expose whether the declaration of * <p> Some methods of class {@code Class} expose whether the declaration of
* a class or interface in Java source code was <em>enclosed</em> within * a class or interface in Java source code was <em>enclosed</em> within
@ -341,9 +340,9 @@ public final class Class<T> implements java.io.Serializable,
* interface with the given string name. Invoking this method is * interface with the given string name. Invoking this method is
* equivalent to: * equivalent to:
* *
* <blockquote> * {@snippet lang="java" :
* {@code Class.forName(className, true, currentLoader)} * Class.forName(className, true, currentLoader)
* </blockquote> * }
* *
* where {@code currentLoader} denotes the defining class loader of * where {@code currentLoader} denotes the defining class loader of
* the current class. * the current class.
@ -352,9 +351,9 @@ public final class Class<T> implements java.io.Serializable,
* runtime {@code Class} descriptor for the class named * runtime {@code Class} descriptor for the class named
* {@code java.lang.Thread}: * {@code java.lang.Thread}:
* *
* <blockquote> * {@snippet lang="java" :
* {@code Class t = Class.forName("java.lang.Thread")} * Class<?> t = Class.forName("java.lang.Thread");
* </blockquote> * }
* <p> * <p>
* A call to {@code forName("X")} causes the class named * A call to {@code forName("X")} causes the class named
* {@code X} to be initialized. * {@code X} to be initialized.
@ -415,15 +414,15 @@ public final class Class<T> implements java.io.Serializable,
* *
* <p> For example, in an instance method the expression: * <p> For example, in an instance method the expression:
* *
* <blockquote> * {@snippet lang="java" :
* {@code Class.forName("Foo")} * Class.forName("Foo")
* </blockquote> * }
* *
* is equivalent to: * is equivalent to:
* *
* <blockquote> * {@snippet lang="java" :
* {@code Class.forName("Foo", true, this.getClass().getClassLoader())} * Class.forName("Foo", true, this.getClass().getClassLoader())
* </blockquote> * }
* *
* Note that this method throws errors related to loading, linking * Note that this method throws errors related to loading, linking
* or initializing as specified in Sections {@jls 12.2}, {@jls * or initializing as specified in Sections {@jls 12.2}, {@jls
@ -607,15 +606,15 @@ public final class Class<T> implements java.io.Serializable,
* *
* <p>The call * <p>The call
* *
* <pre>{@code * {@snippet lang="java" :
* clazz.newInstance() * clazz.newInstance()
* }</pre> * }
* *
* can be replaced by * can be replaced by
* *
* <pre>{@code * {@snippet lang="java" :
* clazz.getDeclaredConstructor().newInstance() * clazz.getDeclaredConstructor().newInstance()
* }</pre> * }
* *
* The latter sequence of calls is inferred to be able to throw * The latter sequence of calls is inferred to be able to throw
* the additional exception types {@link * the additional exception types {@link
@ -2485,7 +2484,7 @@ public final class Class<T> implements java.io.Serializable,
* @apiNote * @apiNote
* <p> The following method can be used to find the record canonical constructor: * <p> The following method can be used to find the record canonical constructor:
* *
* <pre>{@code * {@snippet lang="java" :
* static <T extends Record> Constructor<T> getCanonicalConstructor(Class<T> cls) * static <T extends Record> Constructor<T> getCanonicalConstructor(Class<T> cls)
* throws NoSuchMethodException { * throws NoSuchMethodException {
* Class<?>[] paramTypes = * Class<?>[] paramTypes =
@ -2493,7 +2492,7 @@ public final class Class<T> implements java.io.Serializable,
* .map(RecordComponent::getType) * .map(RecordComponent::getType)
* .toArray(Class<?>[]::new); * .toArray(Class<?>[]::new);
* return cls.getDeclaredConstructor(paramTypes); * return cls.getDeclaredConstructor(paramTypes);
* }}</pre> * }}
* *
* @return An array of {@code RecordComponent} objects representing all the * @return An array of {@code RecordComponent} objects representing all the
* record components of this record class, or {@code null} if this * record components of this record class, or {@code null} if this