Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8029117

(reflect) clarify javadoc for getMethod(...) and getMethods()

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P3
    • Resolution: Fixed
    • Affects Version/s: 1.4.2, 5.0, 6, 7, 8
    • Fix Version/s: 8
    • Component/s: core-libs
    • Labels:

      Backports

        Description

        Since at least jdk4 getMethod(name) and getMethods() called on an interface class does not find/return object methods that are not overridden in a super interface.

        ---

        $ cat TT.java
        import java.lang.reflect.*;
        public class TT {
            public static void main(String[] args) throws Exception {
                System.out.println(TT.class.getMethod("equals", new Class[] {Object.class}));
                System.out.println(I.class.getMethod("equals", new Class[] {Object.class}));
            }
        }

        interface I {}

        $ /localhome/hotspots/old/j2sdk1.4.2/bin/java TT
        public boolean java.lang.Object.equals(java.lang.Object)
        Exception in thread "main" java.lang.NoSuchMethodException: I.equals(java.lang.Object)
        at java.lang.Class.getMethod(Class.java:978)
        at TT.main(TT.java:5

        ---

        $ cat T.java
        import java.lang.reflect.*;
        public class T {
            public static void main(String[] args) {
                Method[] ms = I.class.getMethods();
                for (int i = 0; i < ms.length; i++)
                    System.out.println(ms[i]);
            }
        }

        interface I {}

        $ /localhome/hotspots/old/j2sdk1.4.2/bin/java T
        $

        The javadoc for these methods should be updated to match the longstanding behavior.

          Attachments

            Issue Links

              Activity

                People

                Assignee:
                jfranck Joel Borggrén-Franck (Inactive)
                Reporter:
                jfranck Joel Borggrén-Franck (Inactive)
                Votes:
                0 Vote for this issue
                Watchers:
                4 Start watching this issue

                  Dates

                  Created:
                  Updated:
                  Resolved: