被加载类和加载类的程序在一个文件夹下;
运行没有任何结果:
D:java_exercise>javac URLTest.java
D:java_exercise>java URLTest
D:java_exercise>
加载类:
import java.net.*;
import java.io.File;
import java.net.URLClassLoader ;
public class URLTest
{
public static void main (String [ ] args )
{
URL[ ] urls = new URL[1] ;
try {
urls[0] = new URL("file",null,(new File(System.getProperty("user.dir") + File.separator)).toString ( ) );
URLClassLoader cl = new URLClassLoader ( urls) ;
cl.loadClass ("Testee");
}
catch (Exception e)
{
e.printStackTrace ( ) ;
}
}
}
被加载类:
public class Testee
{
static
{
System.out.println ("I am loaded!");
}
}
The problem lies in when the static code block of the class is executed:
You have just loaded the class and it does not meet the conditions
That’s it