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

Document that reflection methods may have null argument lists

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Fixed
    • Icon: P4 P4
    • 1.4.0
    • 1.2.2, 1.3.0
    • docs
    • beta
    • generic
    • generic



      Name: yyT116575 Date: 09/15/2000


      java version "1.3.0"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.0-C)
      Java HotSpot(TM) Client VM (build 1.3.0-C, mixed mode)

      I wrote a little test program (below) to see if null parameters were allowed
      for the argument list (second parameter) in java.reflect.Class.getDeclaredMethod
      (String, Object[]) and java.reflect.Method.invoke(Object, Object[]). Apparently
      they are. I think this should be documented. Similarly, other reflection
      methods that accept null parameter lists should be documented. There are many
      cases in the core Java class libraries that do something similar to the
      following:

        // m is an instance of Method.
          m.invoke(object, new Object[0]);

      I have seen this pattern used in lots of (third-party) reflection documentation
      too. Perhaps the behavior changed recently?

      A.java
      ---------------
      public class A {
        public static void main(String [] args) {
          A a = new A();
          try {
            java.lang.reflect.Method m = A.class.getDeclaredMethod("printMe", null);
            m.invoke(a, null);
          } catch (Exception e) {
        }
      }

      public void printMe() { System.out.println(this); }
      }
      (Review ID: 109230)
      ======================================================================

            jhosunw Jamie Ho (Inactive)
            yyoungsunw Yung-ching Young (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: