# HG changeset patch # User jfranck # Date 1386151445 -3600 # Node ID fb9a728c4b77e42728acdd9bb31aa9e901134167 # Parent ba91ccb012e623a4b62dcf04dd2cbac99d7062e2 8029117: (reflect) clarify javadoc for getMethod(...) and getMethods() Reviewed-by: darcy diff -r ba91ccb012e6 -r fb9a728c4b77 jdk/src/share/classes/java/lang/Class.java --- a/jdk/src/share/classes/java/lang/Class.java Wed Dec 04 10:27:50 2013 +0100 +++ b/jdk/src/share/classes/java/lang/Class.java Wed Dec 04 11:04:05 2013 +0100 @@ -1565,8 +1565,12 @@ * methods inherited by the array type from {@code Object}. It does not * contain a {@code Method} object for {@code clone()}. * - *

If this {@code Class} object represents a class or interface with no - * public methods, then the returned array has length 0. + *

If this {@code Class} object represents an interface then the + * returned array does not contain any implicitly declared methods from + * {@code Object}. Therefore, if no methods are explicitly declared in + * this interface or any of its superinterfaces then the returned array + * has length 0. (Note that a {@code Class} object which represents a class + * always has public methods, inherited from {@code Object}.) * *

If this {@code Class} object represents a primitive type or void, * then the returned array has length 0. @@ -1699,25 +1703,29 @@ * order. If {@code parameterTypes} is {@code null}, it is * treated as if it were an empty array. * - *

If the {@code name} is "{@code };"or "{@code }" a + *

If the {@code name} is "{@code }" or "{@code }" a * {@code NoSuchMethodException} is raised. Otherwise, the method to * be reflected is determined by the algorithm that follows. Let C be the - * class represented by this object: + * class or interface represented by this object: *

    - *
  1. C is searched for any matching methods. If no matching - * method is found, the algorithm of step 1 is invoked recursively on - * the superclass of C.
  2. - *
  3. If no method was found in step 1 above, the superinterfaces of C - * are searched for a matching method. If any such method is found, it - * is reflected.
  4. + *
  5. C is searched for a matching method, as defined below. If a + * matching method is found, it is reflected.
  6. + *
  7. If no matching method is found by step 1 then: + *
      + *
    1. If C is a class other than {@code Object}, then this algorithm is + * invoked recursively on the superclass of C.
    2. + *
    3. If C is the class {@code Object}, or if C is an interface, then + * the superinterfaces of C (if any) are searched for a matching + * method. If any such method is found, it is reflected.
    4. + *
  8. *
* - * To find a matching method in a class C:  If C declares exactly one - * public method with the specified name and exactly the same formal - * parameter types, that is the method reflected. If more than one such - * method is found in C, and one of these methods has a return type that is - * more specific than any of the others, that method is reflected; - * otherwise one of the methods is chosen arbitrarily. + *

To find a matching method in a class or interface C:  If C + * declares exactly one public method with the specified name and exactly + * the same formal parameter types, that is the method reflected. If more + * than one such method is found in C, and one of these methods has a + * return type that is more specific than any of the others, that method is + * reflected; otherwise one of the methods is chosen arbitrarily. * *

Note that there may be more than one matching method in a * class because while the Java language forbids a class to