Java.lang Package Classes

Java ClassLoader - clearAssertionStatus() Method



The java.lang.ClassLoader.clearAssertionStatus() method is used to set the default assertion status for this class loader to false and discards any package defaults or class assertion status settings associated with the class loader. This method is provided so that class loaders can be made to ignore any command line or persistent assertion status settings and "start with a clean slate."

Syntax

public void clearAssertionStatus()

Parameters

No parameter is required.

Return Value

void type.

Exception

NA.

Example:

The example below shows how to use java.lang.ClassLoader.clearAssertionStatus() method.

import java.lang.*;

public class MyClass {
  public static void main(String[] args) throws ClassNotFoundException {
      //loads the class
      Class cls = Class.forName("MyClass");

      //returns the ClassLoader object 
      //associated with this Class
      ClassLoader cL = cls.getClassLoader();
    
      //print ClassLoader
      System.out.println("ClassLoader: ");
      System.out.println(cL.getClass());
    
      //print parent ClassLoader
      System.out.println("parent ClassLoader: ");
      System.out.println(cL.getParent()); 

      //set the default assertion status to false
      cL.clearAssertionStatus();  
  }
}

The output of the above code will be:

ClassLoader: 
class jdk.internal.loader.ClassLoaders$AppClassLoader
parent ClassLoader: 
jdk.internal.loader.ClassLoaders$PlatformClassLoader@7960847b

❮ Java.lang - ClassLoader