public class ClassFile extends Object
toString()
method, is:
magic: -889275714 minor_version: 0 major_version: 49 access_flags: 33 this_class: ConstantClassInfo HelloWorld super_class: ConstantClassInfo java/lang/Object interfaces_count: 0 fields_count: 0 methods_count: 2 access_flags: 1 name_index: <init> descriptor_index: ()V attributes_count: 1 attribute_name_index: Code max_stack: 1 max_locals: 1 0: 25 0 1: 183 ConstantMethodRefInfo java/lang/Object.<init>()V 2: 177 exception_table_length: 0 attributes_count: 2 attribute_name_index: LineNumberTable line_number_table_length: 1 start_pc: <0> line_number: 31 attribute_name_index: LocalVariableTable local_variable_table_length: 1 start_pc: <0> length: <3> name_index: this descriptor_index: LHelloWorld; index: 0 access_flags: 9 name_index: main descriptor_index: ([Ljava/lang/String;)V attributes_count: 1 attribute_name_index: Code max_stack: 2 max_locals: 1 0: 178 ConstantFieldRefInfo java/lang/System.outLjava/io/PrintStream; 1: 18 ConstantStringInfo Hello, world! 2: 182 ConstantMethodRefInfo java/io/PrintStream.println(Ljava/lang/String;)V 3: 177 exception_table_length: 0 attributes_count: 2 attribute_name_index: LineNumberTable line_number_table_length: 2 start_pc: <0> line_number: 33 start_pc: <3> line_number: 34 attribute_name_index: LocalVariableTable local_variable_table_length: 1 start_pc: <0> length: <4> name_index: args descriptor_index: [Ljava/lang/String; index: 0 attributes_count: 1 attribute_name_index: SourceFile sourcefile_index: HelloWorld.java
This class is used to compare classes in unit tests. Its source code is as close as possible to the Java Virtual Machine specification for ease of reference. The constant pool and bytecode offsets are abstracted away so that two classes which differ only by their constant pool or low level byte code instruction representation (e.g. a ldc vs. a ldc_w) are still considered equal. Likewise, attributes (resp. type annotations) are re-ordered into alphabetical order, so that two classes which differ only via the ordering of their attributes (resp. type annotations) are still considered equal.
Constructor and Description |
---|
ClassFile(byte[] classBytes)
Constructs a new ClassFile instance.
|
Modifier and Type | Method and Description |
---|---|
boolean |
equals(Object other)
Returns whether the given class file is the same as this one.
|
String |
getConstantPoolDump()
Returns a string representation of the constant pool of the class contained in this class file.
|
int |
hashCode()
Returns the hashcode of this class file.
|
Object |
newInstance()
Returns a new instance of the class contained in this class file.
|
String |
toString()
Returns a string representation of this class file.
|
public ClassFile(byte[] classBytes)
classBytes
- the binary content of a Java class file.public String getConstantPoolDump()
public Object newInstance() throws ReflectiveOperationException
ReflectiveOperationException
- if the class is invalid or if an error occurs in its
constructor.public boolean equals(Object other)
equals
in class Object
ClassFile
with the same string representation.ClassFormatException
- if the class content can't be parsed.public int hashCode()
hashCode
in class Object
ClassFormatException
- if the class content can't be parsed.public String toString()
toString
in class Object
ClassFormatException
- if the class content can't be parsed.Copyright © 2020. All rights reserved.