java.lang.instrument.ClassDefinition Class in Java
This class is used to bind together the supplied class and class file bytes in a single ClassDefinition object. These class provide methods to extract information about the type of class and class file bytes of an object. This class is a subclass of java.lang.Object class.
Class declaration:
public final class ClassDefinition
extends Object
Constructor:
Constructor |
Description |
ClassDefinition(Class<?> theClass, byte[] theClassFile) |
This constructor creates a new instance of ClassDefinition class by binding the supplied class and class file bytes. |
Methods:
Method |
Description |
getDefinitionClass() |
This method is used to get the class type of this class |
getDefinitionClassFile() |
This method Is used to get the array of bytes that contains the new class file. |
Example 1: Java program to create new ClassDefinition object
Java
import java.lang.instrument.ClassDefinition;
public class GFG {
static class demoClass {
void msg() { System.out.println( "GeeksForGeeks" ); }
}
public static void main(String[] args)
{
try {
demoClass cls = new demoClass();
Class<?> theClass = cls.getClass();
byte [] classFiles = { 0 };
ClassDefinition classdefinition
= new ClassDefinition(theClass, classFiles);
System.out.println(
"ClassDefinition object successfully created" );
}
catch (Exception e) {
e.printStackTrace();
}
}
}
|
Output
ClassDefinition object successfully created
Example 2: Java program to illustrate ClassDefinition class methods
Java
import java.lang.instrument.ClassDefinition;
public class GFG {
static class demoClass {
void msg() { System.out.println( "GeeksForGeeks" ); }
}
public static void main(String[] args)
{
try {
demoClass cls = new demoClass();
Class<?> theClass = cls.getClass();
byte [] classFiles = { 0 };
ClassDefinition classdefinition
= new ClassDefinition(theClass, classFiles);
System.out.println(
classdefinition.getDefinitionClass());
System.out.println(
classdefinition.getDefinitionClassFile());
}
catch (Exception e) {
e.printStackTrace();
}
}
}
|
Output
class GFG$demoClass
[B@448139f0
Last Updated :
29 Mar, 2021
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...