Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit a133889

Browse files
static 1 修改
1 parent 5aa6a77 commit a133889

File tree

1 file changed

+1
-4
lines changed
  • chapter12 Java模块化/java9-action-static/dockerx-traffic-optional-gui/src/main/java/com/dockerx/traffic/optional/gui

1 file changed

+1
-4
lines changed

‎chapter12 Java模块化/java9-action-static/dockerx-traffic-optional-gui/src/main/java/com/dockerx/traffic/optional/gui/Gui.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,18 @@
1010
public class Gui {
1111
public static void main(String[] args) {
1212
//module-info.java 文件中使用static修饰后,会在编译阶段直接忽略这个类,不会加载到文件系统中,
13-
// 不过想要使用可以通过反射获取,我们有requires的
1413
// 下面注释掉的两条语句都会报ClassNotFoundException
1514
/*Person person = new Person(100, 1);
1615
System.out.println(Person.class.getAnnotations().length);*/
1716

1817
System.out.println(Bike.class.getAnnotations().length);
1918
System.out.println("Running without annotation @Anno present.");
20-
19+
//同样,使用反射也是不行的,会报下面catch到的错了
2120
try {
2221
Class<?> clazz = Class.forName("com.dockerx.traffic.optional.entity.Person");
2322
Person instance =
2423
(Person) clazz.getConstructor().newInstance();
2524
instance.setMileage(10);
26-
//同样,添加下面注释这句,就会报下面catch到的错了
27-
// System.out.println(Person.class.getAnnotations().length);
2825
System.out.println("Using Person");
2926
} catch (ReflectiveOperationException e) {
3027
System.out.println("Oops, we need a fallback!");

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /