问题描述
是否有一些工具或技术可以让我查询Java .class文件的内容?我想知道类的完全限定名称及其定义的方法.我以为javap
可以帮助我解决这个问题,但我不知道如何解决.
Is there some tool or technique to let me query the contents of a Java .class file? I want to know the fully qualified name of the class and what method it defines. I thought that perhaps javap
could help me with this but I can't figure out how.
推荐答案
实际上,是的.我遇到的每个Java实现都依赖于类文件路径名来定位要加载的类,等等.
In practice, yes. Every Java implementation I've come across relies on class file pathnames to locate classes to be loaded, etc.
理论上,类加载器可以使用其他机制,因此可以将类存储在与类名无关的文件中.但是,我认为这样做没有任何优势.
In theory, a classloader could use some other mechanism, and therefore could store classes in files that bear no relation to the class names. However, I see no advantage in doing that.
鉴于这些语言会编译为字节代码文件,然后由标准类加载器加载,那么就可以肯定,字节码文件中的类名称与文件路径名相对应...否则,类加载器不会能够找到类文件.但是,这不一定意味着字节码文件中的类名与源代码中使用的标识符Scala/Jython/Groovy相同.确实,对于Java来说,这甚至都不是正确的.例如匿名类和内部类的类文件名与Java源代码中的标识符不同.
Given that these languages compile to bytecode files that are then loaded by standard class loaders, then it is pretty much a given that the class names in the bytecode files correspond to the file pathnames ... otherwise the class loaders wouldn't be able to locate the class files. However, this does not necessarily mean that the class names in the bytecode files are identical to Scala / Jython / Groovy the identifiers used in the source code. Indeed, this isn't even true for Java; e.g. the classfile names for anonymous and inner classes for not the same as the identifiers in the Java source code.
这篇关于检查.class文件中类的包名称和类名称的工具的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!