从已编译的类文件显示泛型类型参数 [英] Displaying generic type parameters from compiled class files

查看:141
本文介绍了从已编译的类文件显示泛型类型参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有类似于 javap 的工具,可以显示带有原始(未擦除)类型的方法和字段?

我知道当编译源代码时,类型信息是擦除。然而,编译器必须知道,因为它能够确定我的库方法调用是否匹配它们的签名,即使这个库已经编译到类文件中。因此,至少在理论上,应该可以检索类型信息。



我进一步搜索,发现这个答案:

哪些指向我
getGeneric ... ()方法。所以在我看来,类型信息以一种复杂的方式存储在类文件中,并且这些方法允许获取它。但到目前为止,我没有找到一个能够显示这些信息的(命令行)工具。

解决方案

反编译器 http://java.decompiler.free.fr/ 会给你一个近似的原始源代码,包括通用签名。

Is there a tool similar to javap that could display methods and fields with their original (non-erased) types?

I know that the type information is erased when source code is compiled. However, the compiler must know somehow, because it is able to determine if my calls to library methods match their signatures even if the library is already compiled into class files. So at least in theory, it should be possible to retrieve the type information.

I searched further and I found this answer: Where are generic types stored in java class files? which pointed me to getGeneric...() methods. So it looks to me that the type information is stored in class files in some complicated way, and these methods allow to obtain it. But so far I didn't find a (command line) tool that'd display this information.

解决方案

A decompiler such as http://java.decompiler.free.fr/ will give you an approximation to the original source code, including the generic signatures.

这篇关于从已编译的类文件显示泛型类型参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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