Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do we see the bytecode generated by the compiler for type erasure in Java [duplicate]

Possible Duplicate:
How to view Java's byte code?

I want to know whether is it possible to see the code changes done by the java compiler in the class file after type erasure.

I have tried javap, but it rebuilds the original source file with the parametrized types.

The tutorial (http://docs.oracle.com/javase/tutorial/java/generics/genTypes.html) talks about replacement of parametrized type with a bounded type or an Object after type erasure. I want to see what changes are done by the compiler which is not visible with javap or any decompiler.

regards, sathwik

like image 888
Sathwik Avatar asked Nov 13 '22 02:11

Sathwik


1 Answers

Type erasure literally means the generic type is dropped from the resulting byte code. It is notable by its absence. As such, all you can see that it is not there in the byte code.

When you use javap, you will see that some generic type information is available for class, method and field signatures. This is included so the compiler can do its job to compile code using these classes. They don't do anything at runtime, although they are available via reflection so you can write a library which uses this information.

like image 163
Peter Lawrey Avatar answered Nov 30 '22 22:11

Peter Lawrey