当使用 java 命令运行 java 程序时,您可以使用 -verbose 指定详细选项,它允许您检查何时加载类。例如:
java -verbose Test | grep "file:"
[Loaded Test from file:/Users... ]
[Loaded C1 from file:/Users... ]
[Loaded A1 from file:/Users... ]
[Loaded B1 from file:/Users...]
[Loaded C2 from file:/Users...]
有没有办法指示验证阶段何时发生?类的验证不一定在加载后直接进行。例如,这样的事情将是理想的:
java -verbose Test | grep "file:"
[Loaded Test from file:/Users... ]
[Loaded C1 from file:/Users... ]
[Loaded A1 from file:/Users... ]
[Loaded B1 from file:/Users...]
[Verified C1]
[Loaded C2 from file:/Users...]
[Verified C2]
ETC
对于那些“你不需要这个”,“你为什么要这样做”的答案。它只是出于纯粹的兴趣,仍然值得提问。