ClassLoader.clearAssertionStatus() 方法
描述
java.lang.ClassLoader.clearAssertionStatus() 方法将此类加载器的默认断言状态设置为 false,并丢弃与类加载器关联的任何包默认值或类断言状态设置。
提供此方法是为了使类加载器可以忽略任何命令行或持久性断言状态设置并从头开始。
声明
以下是 java.lang.ClassLoader.clearAssertionStatus() 方法的声明。
public void clearAssertionStatus()
参数
NA
返回值
此方法不返回任何值。
异常
NA
示例
下面的例子展示了 java.lang.ClassLoader.clearAssertionStatus() 方法的使用。
package com.tutorialspoint;
import java.lang.*;
public class ClassLoaderDemo {
public static void main(String[] args) throws Exception {
Class cls = Class.forName("ClassLoaderDemo");
// returns the ClassLoader object associated with this Class
ClassLoader cLoader = cls.getClassLoader();
System.out.println(cLoader.getClass());
// returns the parent ClassLoader
System.out.println(cLoader.getParent());
// sets the default assertion status to false
cLoader.clearAssertionStatus();
}
}
让我们编译并运行上面的程序,这将产生下面的结果 −
class sun.misc.Launcher$AppClassLoader sun.misc.Launcher$ExtClassLoader@35ce36

