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

Ad: Are you a blogger? Join our Blogging forum.




Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates


© https://www.includehelp.com some rights reserved.