1、使用javac编译Java文件
2、使用javap -verbose查看class字节码文件
2.1 使用-g:none或-g:lines选项来取消或要求生成LineNumberTable
2.2 使用-g:none或-g:vars选项来取消或要求生成LocalVariableTable
2.3 实例
D:\>javac -g:lines -g:vars Test.java
3、实例:
3.1 实例代码
public class Test { public int getInt(){ int a = 1; return a; } }
3.2 编译
D:\>javac Test.java
3.3 查看class文件
D:\>javap -verbose Test Classfile /D:/Test.class Last modified 2016-6-6; size 243 bytes MD5 checksum a140b97d207299f2d645e25fc1552334 Compiled from "Test.java" public class Test SourceFile: "Test.java" minor version: 0 major version: 51 flags: ACC_PUBLIC, ACC_SUPER Constant pool: #1 = Methodref #3.#12 // java/lang/Object."<init>":()V #2 = Class #13 // Test #3 = Class #14 // java/lang/Object #4 = Utf8 <init> #5 = Utf8 ()V #6 = Utf8 Code #7 = Utf8 LineNumberTable #8 = Utf8 getInt #9 = Utf8 ()I #10 = Utf8 SourceFile #11 = Utf8 Test.java #12 = NameAndType #4:#5 // "<init>":()V #13 = Utf8 Test #14 = Utf8 java/lang/Object { public Test(); flags: ACC_PUBLIC Code: stack=1, locals=1, args_size=1 0: aload_0 1: invokespecial #1 // Method java/lang/Object."<init> ":()V 4: return LineNumberTable: line 1: 0 public int getInt(); flags: ACC_PUBLIC Code: stack=1, locals=2, args_size=1 0: iconst_1 1: istore_1 2: iload_1 3: ireturn LineNumberTable: line 4: 0 line 5: 2 }
时间: 2024-11-09 03:31:10