检查.class文件中类的包名称和类名称的工具 [英] Tool to check package name and class name of the class within a .class file

查看:92
本文介绍了检查.class文件中类的包名称和类名称的工具的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有一些工具或技术可以让我查询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.

推荐答案

.class文件中包含的类是否始终与文件名相同(.class除外)

Is the class contained in the .class file always the same as the file name (excluding .class)

实际上,是的.我遇到的每个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.

即使我使用Groovy,Jython或Scala等其他语言?

even if I use some other language such as Groovy, Jython or Scala?

鉴于这些语言会编译为字节代码文件,然后由标准类加载器加载,那么就可以肯定,字节码文件中的类名称与文件路径名相对应...否则,类加载器不会能够找到类文件.但是,这不一定意味着字节码文件中的类名与源代码中使用的标识符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文件中类的包名称和类名称的工具的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆