Home » Java programming language

Java ClassLoader setDefaultAssertionStatus() method with example

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

ClassLoader Class setDefaultAssertionStatus() method

  • setDefaultAssertionStatus() method is available in java.lang package.
  • setDefaultAssertionStatus() method is used to sets the default assertion status for this class loader to load the class. If, we use class loaded by this class loader later will have assertion enabled or disabled by default.
  • setDefaultAssertionStatus() 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.
  • setDefaultAssertionStatus() method does not throw an exception at the time of set default assertion status of the class.

Syntax:

    public void setDefaultAssertionStatus(boolean status);

Parameter(s):

  • boolean status – represents the status of assertions it returns true when class loaded by this class loader will have assertion enabled by default.

Return value:

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

Example:

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

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

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

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

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

  // By using setDefaultAssertionStatus() method is to set the 
  //the default status 
  loader.setDefaultAssertionStatus(true);
 }
}

Output

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


Comments and Discussions!

Load comments ↻





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