changeset 14746:d6a1ad87842f

8159330: Improve deprecation text for Class.newInstance Reviewed-by: rriggs, weijun
author darcy
date Tue, 14 Jun 2016 09:03:12 -0700
parents 1377b7b21992
children 7c5272d4ab6c 965aca494570
files src/java.base/share/classes/java/lang/Class.java
diffstat 1 files changed, 18 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/src/java.base/share/classes/java/lang/Class.java	Tue Jun 14 12:29:49 2016 +0900
+++ b/src/java.base/share/classes/java/lang/Class.java	Tue Jun 14 09:03:12 2016 -0700
@@ -480,6 +480,24 @@
      * any exception thrown by the constructor in a (checked) {@link
      * java.lang.reflect.InvocationTargetException}.
      *
+     * <p>The call
+     *
+     * <pre>{@code
+     * clazz.newInstance()
+     * }</pre>
+     *
+     * can be replaced by
+     *
+     * <pre>{@code
+     * clazz.getConstructor().newInstance()
+     * }</pre>
+     *
+     * The latter sequence of calls is inferred to be able to throw
+     * the additional exception types {@link
+     * InvocationTargetException} and {@link
+     * NoSuchMethodException}. Both of these exception types are
+     * subclasses of {@link ReflectiveOperationException}.
+     *
      * @return  a newly allocated instance of the class represented by this
      *          object.
      * @throws  IllegalAccessException  if the class or its nullary