⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 settrace.java

📁 it contains the practical programs in our college
💻 JAVA
字号:
import java.lang.reflect.Field;import static java.lang.System.out;enum TraceLevel { OFF, LOW, MEDIUM, HIGH, DEBUG }class MyServer {    private TraceLevel level = TraceLevel.OFF;}public class SetTrace {    public static void main(String... args) {	TraceLevel newLevel = TraceLevel.valueOf(args[0]);	try {	    MyServer svr = new MyServer();	    Class<?> c = svr.getClass();	    Field f = c.getDeclaredField("level");	    f.setAccessible(true);	    TraceLevel oldLevel = (TraceLevel)f.get(svr);	    out.format("Original trace level:  %s%n", oldLevel);	    if (oldLevel != newLevel) { 		f.set(svr, newLevel);		out.format("    New  trace level:  %s%n", f.get(svr));	    }        // production code should handle these exceptions more gracefully	} catch (IllegalArgumentException x) {	    x.printStackTrace();	} catch (IllegalAccessException x) {	    x.printStackTrace();	} catch (NoSuchFieldException x) {	    x.printStackTrace();	}    }}

⌨️ 快捷键说明

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