Home » Java programming language

Java ClassLoader setClassAssertionStatus() method with example

ClassLoader Class setClassAssertionStatus() method: Here, we are going to learn about the setClassAssertionStatus() method of ClassLoader Class with its syntax and example.
Submitted by Preeti Jain, on November 24, 2019

ClassLoader Class setClassAssertionStatus() method

  • setClassAssertionStatus() method is available in java.lang package.
  • setClassAssertionStatus() method is used to sets the assertion status for the named top-level class in this class loader or any nested classes contains in the class loader.
  • setClassAssertionStatus() method is a non-static method, it is accessible with the class object only and if we try to access the method with the class name then we will get an error.
  • setClassAssertionStatus() method does not throw an exception at the time of the set assertion status of the class.

Syntax:

    public void setClassAssertionStatus(String cl_name, boolean status);

Parameter(s):

  • String cl_name – represents the fully qualified name of the top-level class whose assertion status is to be set.
  • boolean status – represents the status of assertions when the named class is to have assertion enabled. It returns true and when the named class is to have assertion disabled, it returns false.

Return value:

The return type of this method is void, it returns nothing.

Example:

// Java program to demonstrate the example 
// of void setClassAssertionStatus () method of ClassLoader 

public class setClassAssertionStatusOfClassLoader {
 public static void main(String[] args) throws Exception {

  // Load a class
  Class cl = Class.forName("setClassAssertionStatusOfClassLoader");

  // It returns the ClassLoader associated with the
  // class Object
  ClassLoader loader = cl.getClassLoader();

  // Display loader
  System.out.println("loader Class: " + loader.getClass());

  // By using setClassAssertionStatus() method is to set the 
  //desired status and sets the status to true
  loader.setClassAssertionStatus("setClassAssertionStatusOfClassLoader", true);
 }
}

Output

loader Class: class jdk.internal.loader.ClassLoaders$AppClassLoader


Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.