类文件解析器 [英] Class file parser
本文介绍了类文件解析器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个作业,需要编写一个Java程序来解析.class文件并检索类似的内容:
I have an assignment where i need to write a Java program that parses a .class file and retrieves things like :
1.java文件的名称
1.name of the .java file
2.已实现的接口
3.变量
4.构造函数
5.方法
我没有任何从哪里开始的想法? 例如,我应该使用哪种数据I/O结构?
I don't have any ideeas where to begin from? For example,what kind of Data I/O structure should I use?
推荐答案
您不需要任何外部库,只需使用java.lang.Class
.输入您的班级名称:
You don't need any external library, just use java.lang.Class
. Write the name of your class:
[NameOfMyClass].class.getDeclaredFields();
[NameOfMyClass].class.getDeclaredConstructors();
[NameOfMyClass].class.getDeclaredMethods();
接口和许多其他属性都是相同的.
It's the same for interfaces and many other attributes.
这篇关于类文件解析器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文