processclassinst.java

来自「基于LWVCL开发的库」· Java 代码 · 共 84 行

JAVA
84
字号
/** * ??? * * @author Godmar Back <gback@cs.utah.edu> */import java.util.Vector;class Base {    static boolean useme;    static {	Base b = new Base();	ProcessClassInst.v.addElement(b);	useme = true;	try {	    Thread.sleep(2000);	} catch (InterruptedException e) { }	((Object)null).toString();    }    public String toString() { return "a base"; }}public class ProcessClassInst{    static Vector v = new Vector();    public static void main(String av[]) throws Exception {	// a watchdog thread that kills us off after 9 sec	Thread wd = new Thread() {	    public void run() {		try {		    Thread.sleep(9000);		    System.out.println("sorry, you timed out");		    System.exit(-1);		} catch (Exception e) {		    System.out.println(e);		}	    }	};	wd.setDaemon(true);	wd.start();	// a thread that will load Base	Thread t = new Thread() {	    public void run() {		try {		    Class.forName("Base");		} catch (Throwable tx) {		    // System.out.println(tx);		}	    }	};	t.start();	Thread.sleep(1000);	// nobody knows yet whether that should succeed...	Thread t0 = new Thread() {	    public void run() {		try {		    System.out.println("tan " + new Base());		} catch (Throwable tt) {		    System.out.println("tan " + tt);		}	    }	};	t0.start();	t0.join();	Class cc = v.elementAt(0).getClass();	try {		cc.newInstance();	}	catch (NoClassDefFoundError e) {		System.out.println(e);	}    }}/* Expected Output:tan java.lang.NoClassDefFoundError: Basejava.lang.NoClassDefFoundError: Base*/

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?