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 very good tool for looking around in a
.class
is JClasslib. It's a much better alternative thanjavap
. An example screenshot:You can use it to view all fields inside a
.class
file, all methods, the byte code, everything. It can also open JAR files.You can look in the "Attributes" Section -> Signature. You can find such information there.
For example: For the following class definition:
I can see something like this:
A decompiler such as http://java.decompiler.free.fr/ will give you an approximation to the original source code, including the generic signatures.
You are using an old version of
javap
.You can try
Method.toGenericString()
and it seems everything that you can get from class in runtime. This method should print method signature with generic boundaries.