Skip to content

Commit ca35d1f

Browse files
committed
doc update and cleaning
1 parent 523736c commit ca35d1f

File tree

2 files changed

+44
-6
lines changed

2 files changed

+44
-6
lines changed

README.md

Lines changed: 42 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ This property holds regardless of whether any packages are exported.
3737
`Hibernate` inject values into nonpublic fields of classes.
3838

3939
## project content
40-
### **moduleA**
40+
### moduleA
4141
```
4242
module moduleA {
4343
exports moduleA.export;
@@ -54,8 +54,7 @@ to it. For example if you uncomment the line in `moduleB.TestB`:
5454
// InternalA internalA; // no access
5555
```
5656
project will not compile.
57-
58-
### **moduleB**
57+
### moduleB
5958
```
6059
module moduleB {
6160
requires transitive moduleA;
@@ -78,7 +77,7 @@ Note that we have to put `moduleA` also in `pom.xml` (without `pom.xml`
7877
we should add `moduleA` to `module-path` of `moduleB` otherwise project
7978
will not compile).
8079

81-
### **moduleC**
80+
### moduleC
8281
```
8382
module moduleC {
8483
requires moduleB;
@@ -112,3 +111,42 @@ exported only to `moduleB` (`moduleB.TestB`)
112111
```
113112
ExportA.export();
114113
```
114+
____
115+
### reflection
116+
Module with only one simple class `Invoker` to invoker static methods:
117+
```
118+
public static void invokeStatic(Object obj, String methodName) throws IllegalAccessException {
119+
try {
120+
obj.getClass().getMethod(methodName).invoke(null);
121+
} catch (InvocationTargetException | NoSuchMethodException e) {
122+
throw new RuntimeException(e);
123+
}
124+
}
125+
```
126+
127+
### openModule
128+
```
129+
open module openModule {
130+
requires reflection;
131+
}
132+
```
133+
Running `openModule.Test` class will cause printing to console: "Hello
134+
from openModule!" - because of that the modul is marked as `open` in the
135+
`module-info.java` file.
136+
137+
### ordinaryModule
138+
```
139+
module ordinaryModule {
140+
requires reflection;
141+
}
142+
```
143+
Running `ordinaryModule.Test` class will cause printing to console:
144+
```
145+
java.lang.IllegalAccessException: class Invoker (in module reflection) cannot access class
146+
Test (in module ordinaryModule) because module ordinaryModule does not export ordinaryModule
147+
to module reflection
148+
```
149+
150+
## remarks
151+
* If we are using `maven` the file `module-info.java` should be added to
152+
* asd

reflection/src/main/java/reflection/Invoker.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
* Created by mtumilowicz on 2018-05-11.
77
*/
88
public class Invoker {
9-
public static Object invokeStatic(Object obj, String methodName) throws IllegalAccessException {
9+
public static void invokeStatic(Object obj, String methodName) throws IllegalAccessException {
1010
try {
11-
return obj.getClass().getMethod(methodName).invoke(null);
11+
obj.getClass().getMethod(methodName).invoke(null);
1212
} catch (InvocationTargetException | NoSuchMethodException e) {
1313
throw new RuntimeException(e);
1414
}

0 commit comments

Comments
 (0)