Skip to content

Commit ae7acbf

Browse files
authored
Merge pull request #117 from Maia-Everett/invoke_a_method
Invoke a Method: Clarify how the first argument works for static methods
2 parents c94e213 + d616006 commit ae7acbf

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

src/reflection/invoke_a_method.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class Tea {
3737
```
3838

3939
For static methods you do not need an instance of the class to invoke them.
40-
Instead you need to pass the class itself as the first argument to `.invoke`.
40+
Instead, the first argument is ignored. You can pass `null`.
4141

4242
```java
4343
import java.lang.reflect.InvocationTargetException;
@@ -55,8 +55,8 @@ class Main {
5555
throw new RuntimeException(e);
5656
}
5757

58-
biteMethod.invoke(Apple.class, 5);
59-
biteMethod.invoke(Apple.class, 1);
58+
biteMethod.invoke(null, 5);
59+
biteMethod.invoke(null, 1);
6060
}
6161
}
6262

0 commit comments

Comments
 (0)