Home » Java programming language

Java ClassLoader setPackageAssertionStatus() method with example

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

ClassLoader Class setPackageAssertionStatus() method

  • setPackageAssertionStatus() method is available in java.lang package.
  • setPackageAssertionStatus() method is used to sets the package assertion status for the named package and this default status determines the classes instantiated in the future belong to named package or any of its child package.
  • setPackageAssertionStatus() 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.
  • setPackageAssertionStatus() method does not throw an exception at the time of the set assertion status of the package.

Syntax:

    public void setPackageAssertionStatus (String pack_name, boolean status);

Parameter(s):

  • String pack_name – represents the name of the package whose default assertion status is to be set.
  • boolean status – It sets true when class loaded by this loader and belongs to the given named package will have assertion true by default otherwise 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 setPackageAssertionStatus () method of ClassLoader 

public class setPackageAssertionStatusOfClassLoader {
 public static void main(String[] args) throws Exception {
  // Load a class
  Class cl = Class.forName("setPackageAssertionStatusOfClassLoader");

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

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

  // By using setPackageAssertionStatus() method is to set the 
  // assertion status of the given package
  loader.setPackageAssertionStatus("java.util", 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.