8159330: Improve deprecation text for Class.newInstance
authordarcy
Tue, 14 Jun 2016 09:03:12 -0700
changeset 38951 077499b63957
parent 38950 89fe9dae591e
child 38952 ca428fb526d4
child 38959 e4dec0a22af2
8159330: Improve deprecation text for Class.newInstance Reviewed-by: rriggs, weijun
jdk/src/java.base/share/classes/java/lang/Class.java
--- a/jdk/src/java.base/share/classes/java/lang/Class.java	Tue Jun 14 12:29:49 2016 +0900
+++ b/jdk/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