java:javap
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| java:javap [2023/04/12 11:52] – odefta | java:javap [2023/07/04 16:36] (current) – external edit 127.0.0.1 | ||
|---|---|---|---|
| Line 45: | Line 45: | ||
| } | } | ||
| </ | </ | ||
| + | <note tip>We want to check if all the generic types are erased after the compilation.</ | ||
| + | <note important> | ||
| + | It is located in the JAVA_HOME\bin folder. | ||
| + | </ | ||
| + | |||
| + | Command to disassemble the Erasure class is: | ||
| + | < | ||
| + | C: | ||
| + | </ | ||
| + | |||
| + | <note tip>-c parameter is used to display the disassembled code.</ | ||
| + | |||
| + | Result: | ||
| + | < | ||
| + | public ro.medjava.generics.Erasure(); | ||
| + | Code: | ||
| + | 0: aload_0 | ||
| + | 1: invokespecial #1 // Method java/ | ||
| + | 4: return | ||
| + | |||
| + | public static void doStuff1(java.util.List< | ||
| + | Code: | ||
| + | 0: return | ||
| + | |||
| + | public static <E> void doStuff2(java.util.List< | ||
| + | Code: | ||
| + | 0: return | ||
| + | |||
| + | public static void main(java.lang.String[]); | ||
| + | Code: | ||
| + | 0: new # | ||
| + | 3: dup | ||
| + | 4: iconst_1 | ||
| + | 5: anewarray | ||
| + | 8: dup | ||
| + | 9: iconst_0 | ||
| + | 10: ldc # | ||
| + | 12: aastore | ||
| + | 13: invokestatic | ||
| + | 16: invokespecial #6 // Method java/ | ||
| + | 19: invokestatic | ||
| + | 22: return | ||
| + | </ | ||
| + | |||
| + | As we can see in the parameter list of doStuff1 and doStuff2 methods, the generic types survived after compilation.\\ | ||
| + | Some consistency checking information still remains in the binary.\\ | ||
| + | But in the main method, the array list passed to the doStuff2 method does not contain any generic type after compilation. | ||
| + | |||
| + | ===== Use javap in Intellij IDEA ===== | ||
| + | |||
| + | Install the plugin "Class Decompile." | ||
| + | |||
| + | {{: | ||
| + | |||
| + | {{: | ||
| + | |||
| + | Next, right click on your class and select "Show Decompile Code" option. | ||
| + | Result: | ||
| + | |||
| + | {{: | ||
| + | |||
java/javap.1681300371.txt.gz · Last modified: (external edit)
