D:\JavaProject\SpringProject\demo_spring_Synchronized\target\classes\july\wild\demo11>javap -v -p Test06.class Classfile /D:/JavaProject/SpringProject/demo_spring_Synchronized/target/classes/july/wild/demo11/Test06.class Last modified 2020年8月3日; size 380 bytes MD5 checksum 3d6bee6c0a5d3d2000866ed1bad13d03 Compiled from "Test06.java" public class july.wild.demo11.Test06 minor version: 0 major version: 55 flags: (0x0021) ACC_PUBLIC, ACC_SUPER this_class: #2 // july/wild/demo11/Test06 super_class: #3 // java/lang/Object interfaces: 0, fields: 1, methods: 2, attributes: 1 Constant pool: #1 = Methodref #3.#16 // java/lang/Object."<init>":()V #2 = Class #17 // july/wild/demo11/Test06 #3 = Class #18 // java/lang/Object #4 = Utf8 dog #5 = Utf8 Ljuly/wild/demo11/Dog; #6 = Utf8 <init> #7 = Utf8 ()V #8 = Utf8 Code #9 = Utf8 LineNumberTable #10 = Utf8 LocalVariableTable #11 = Utf8 this #12 = Utf8 Ljuly/wild/demo11/Test06; #13 = Utf8 test #14 = Utf8 SourceFile #15 = Utf8 Test06.java #16 = NameAndType #6:#7 // "<init>":()V #17 = Utf8 july/wild/demo11/Test06 #18 = Utf8 java/lang/Object { july.wild.demo11.Dog dog; descriptor: Ljuly/wild/demo11/Dog; flags: (0x0000) public july.wild.demo11.Test06(); descriptor: ()V flags: (0x0001) 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 9: 0 LocalVariableTable: Start Length Slot Name Signature 0 5 0 this Ljuly/wild/demo11/Test06; void test(); descriptor: ()V flags: (0x0000) Code: stack=0, locals=1, args_size=1 0: return LineNumberTable: line 14: 0 LocalVariableTable: Start Length Slot Name Signature 0 1 0 this Ljuly/wild/demo11/Test06; } SourceFile: "Test06.java"
D:\JavaProject\SpringProject\demo_spring_Synchronized\target\classes\july\wild\demo11>javap -v -p Test06.class Classfile /D:/JavaProject/SpringProject/demo_spring_Synchronized/target/classes/july/wild/demo11/Test06.class Last modified 2020年8月3日; size 380 bytes MD5 checksum 3d6bee6c0a5d3d2000866ed1bad13d03 Compiled from "Test06.java" public class july.wild.demo11.Test06 minor version: 0 major version: 55 flags: (0x0021) ACC_PUBLIC, ACC_SUPER this_class: #2 // july/wild/demo11/Test06 super_class: #3 // java/lang/Object interfaces: 0, fields: 1, methods: 2, attributes: 1 Constant pool: #1 = Methodref #3.#16 // java/lang/Object."<init>":()V #2 = Class #17 // july/wild/demo11/Test06 #3 = Class #18 // java/lang/Object #4 = Utf8 dog #5 = Utf8 Ljuly/wild/demo11/Dog; #6 = Utf8 <init> #7 = Utf8 ()V #8 = Utf8 Code #9 = Utf8 LineNumberTable #10 = Utf8 LocalVariableTable #11 = Utf8 this #12 = Utf8 Ljuly/wild/demo11/Test06; #13 = Utf8 test #14 = Utf8 SourceFile #15 = Utf8 Test06.java #16 = NameAndType #6:#7 // "<init>":()V #17 = Utf8 july/wild/demo11/Test06 #18 = Utf8 java/lang/Object { july.wild.demo11.Dog dog; descriptor: Ljuly/wild/demo11/Dog; flags: (0x0000) public july.wild.demo11.Test06(); descriptor: ()V flags: (0x0001) 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 9: 0 LocalVariableTable: Start Length Slot Name Signature 0 5 0 this Ljuly/wild/demo11/Test06; void test(); descriptor: ()V flags: (0x0000) Code: stack=0, locals=1, args_size=1 0: return LineNumberTable: line 14: 0 LocalVariableTable: Start Length Slot Name Signature 0 1 0 this Ljuly/wild/demo11/Test06; } SourceFile: "Test06.java"
上面是两段代码的反编译之后的结果:
一个实例化了Dog 一个没有,从反编译结果看出:内部类的特点Dog():Dog被实例化就会加载Dog类,没有实例化则不会加载Dog类