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)
======================================================================
- duplicates
-
JDK-4273596 Can args param of Method.invoke() be null?
-
- Closed
-