| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
import java.lang.reflect.Method; |
| 18 |
import java.lang.reflect.InvocationTargetException; |
| 19 |
|
| 20 |
public class Main { |
| 21 |
public static void main(String[] args) throws Exception { |
| 22 |
Class<?> c = Class.forName("Test"); |
| 23 |
Method test = c.getDeclaredMethod("test", int[].class); |
| 24 |
assertIntEquals(-2, (int)test.invoke(null, new Object[] { null })); |
| 25 |
assertIntEquals(-1, (int)test.invoke(null, new Object[] { new int[0] })); |
| 26 |
assertIntEquals(42, (int)test.invoke(null, new Object[] { new int[] { 42 } })); |
| 27 |
|
| 28 |
Method test2 = c.getDeclaredMethod("test2", int[].class, int.class); |
| 29 |
assertIntEquals(-2, (int)test2.invoke(null, new Object[] { null, 0 })); |
| 30 |
assertIntEquals(-1, (int)test2.invoke(null, new Object[] { new int[0], 0 })); |
| 31 |
assertIntEquals(-1, (int)test2.invoke(null, new Object[] { new int[0], 1 })); |
| 32 |
assertIntEquals(3, (int)test2.invoke(null, new Object[] { new int[] { 42 }, 0 })); |
| 33 |
} |
| 34 |
|
| 35 |
public static void assertIntEquals(int expected, int result) { |
| 36 |
if (expected != result) { |
| 37 |
throw new Error("Expected: " + expected + ", found: " + result); |
| 38 |
} |
| 39 |
} |
| 40 |
|
| 41 |
|
| 42 |
static final boolean PLACEHOLDER = false; |
| 43 |
} |