解语法糖之私有构造函数

Posted extjs4

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了解语法糖之私有构造函数相关的知识,希望对你有一定的参考价值。

 

package com.test18;
class Outer {
    private Outer(String... a) {     }
    class AOuter extends Outer {
        public AOuter() {
            super("a", "b");
        }
    }
}

 

 

class Outer$AOuter extends Outer {
    /*synthetic*/ final Outer this$0;    
    public Outer$AOuter(/*synthetic*/ final Outer this$0) {
        this.this$0 = this$0;
        super(new String[]{"a", "b"}, null);
    }
}

/*synthetic*/ class Outer$1 {  }

class Outer {
	
    /*synthetic*/ Outer(String[] x0, com.test18.Outer$1 x1) { 
    	this(x0); 
    }
    {   }    
    private Outer(String... a) {   super(); }
    {   }
}

  

  

 

Classfile /C:/Outer.class
  Last modified 2018-7-21; size 431 bytes
  MD5 checksum f9fb0902bfd917d1a14f0a7002a1c52a
  Compiled from "TestScope.java"
class com.test18.Outer
  SourceFile: "TestScope.java"
  InnerClasses:
       static #5 of #3; //class com/test18/Outer$1 of class com/test18/Outer
       #9= #8 of #3; //AOuter=class com/test18/Outer$AOuter of class com/test18/Outer
  minor version: 0
  major version: 51
  flags: ACC_SUPER
Constant pool:
   #1 = Methodref          #3.#17         //  com/test18/Outer."<init>":([Ljava/lang/String;)V
   #2 = Methodref          #4.#18         //  java/lang/Object."<init>":()V
   #3 = Class              #19            //  com/test18/Outer
   #4 = Class              #20            //  java/lang/Object
   #5 = Class              #21            //  com/test18/Outer$1
   #6 = Utf8
   #7 = Utf8               InnerClasses
   #8 = Class              #22            //  com/test18/Outer$AOuter
   #9 = Utf8               AOuter
  #10 = Utf8               <init>
  #11 = Utf8               ([Ljava/lang/String;)V
  #12 = Utf8               Code
  #13 = Utf8               LineNumberTable
  #14 = Utf8               ([Ljava/lang/String;Lcom/test18/Outer$1;)V
  #15 = Utf8               SourceFile
  #16 = Utf8               TestScope.java
  #17 = NameAndType        #10:#11        //  "<init>":([Ljava/lang/String;)V
  #18 = NameAndType        #10:#23        //  "<init>":()V
  #19 = Utf8               com/test18/Outer
  #20 = Utf8               java/lang/Object
  #21 = Utf8               com/test18/Outer$1
  #22 = Utf8               com/test18/Outer$AOuter
  #23 = Utf8               ()V
{
  com.test18.Outer(java.lang.String[], com.test18.Outer$1);
    flags: ACC_SYNTHETIC
    Code:
      stack=2, locals=3, args_size=3
         0: aload_0
         1: aload_1
         2: invokespecial #1                  // Method "<init>":([Ljava/lang/String;)V
         5: return
      LineNumberTable:
        line 3: 0
}

 

Classfile /C:/Outer$1.class
  Last modified 2018-7-21; size 192 bytes
  MD5 checksum 1734aca70f81eb4db6129e52b05ad3e2
  Compiled from "TestScope.java"
class com.test18.Outer$1
  SourceFile: "TestScope.java"
  EnclosingMethod: #6.#0                  // com.test18.Outer
  InnerClasses:
       static #1 of #6; //class com/test18/Outer$1 of class com/test18/Outer
  minor version: 0
  major version: 51
  flags: ACC_SUPER, ACC_SYNTHETIC
Constant pool:
   #1 = Class              #7             //  com/test18/Outer$1
   #2 = Class              #10            //  java/lang/Object
   #3 = Utf8               SourceFile
   #4 = Utf8               TestScope.java
   #5 = Utf8               EnclosingMethod
   #6 = Class              #11            //  com/test18/Outer
   #7 = Utf8               com/test18/Outer$1
   #8 = Utf8
   #9 = Utf8               InnerClasses
  #10 = Utf8               java/lang/Object
  #11 = Utf8               com/test18/Outer
{
}

  

Classfile /C:/Outer$AOuter.class
  Last modified 2018-7-21; size 456 bytes
  MD5 checksum 60e4c039f01fe779661c72038363ca4f
  Compiled from "TestScope.java"
class com.test18.Outer$AOuter extends com.test18.Outer
  SourceFile: "TestScope.java"
  InnerClasses:
       #22= #6 of #7; //AOuter=class com/test18/Outer$AOuter of class com/test18/Outer
       static #25 of #7; //class com/test18/Outer$1 of class com/test18/Outer
  minor version: 0
  major version: 51
  flags: ACC_SUPER
Constant pool:
   #1 = Fieldref           #6.#16         //  com/test18/Outer$AOuter.this$0:Lcom/test18/Outer;
   #2 = Class              #17            //  java/lang/String
   #3 = String             #18            //  a
   #4 = String             #19            //  b
   #5 = Methodref          #7.#20         //  com/test18/Outer."<init>":([Ljava/lang/String;Lcom/test18/Outer$1;)V
   #6 = Class              #21            //  com/test18/Outer$AOuter
   #7 = Class              #24            //  com/test18/Outer
   #8 = Utf8               this$0
   #9 = Utf8               Lcom/test18/Outer;
  #10 = Utf8               <init>
  #11 = Utf8               (Lcom/test18/Outer;)V
  #12 = Utf8               Code
  #13 = Utf8               LineNumberTable
  #14 = Utf8               SourceFile
  #15 = Utf8               TestScope.java
  #16 = NameAndType        #8:#9          //  this$0:Lcom/test18/Outer;
  #17 = Utf8               java/lang/String
  #18 = Utf8               a
  #19 = Utf8               b
  #20 = NameAndType        #10:#27        //  "<init>":([Ljava/lang/String;Lcom/test18/Outer$1;)V
  #21 = Utf8               com/test18/Outer$AOuter
  #22 = Utf8               AOuter
  #23 = Utf8               InnerClasses
  #24 = Utf8               com/test18/Outer
  #25 = Class              #28            //  com/test18/Outer$1
  #26 = Utf8
  #27 = Utf8               ([Ljava/lang/String;Lcom/test18/Outer$1;)V
  #28 = Utf8               com/test18/Outer$1
{
  final com.test18.Outer this$0;
    flags: ACC_FINAL, ACC_SYNTHETIC

  public com.test18.Outer$AOuter(com.test18.Outer);
    flags: ACC_PUBLIC
    Code:
      stack=5, locals=2, args_size=2
         0: aload_0
         1: aload_1
         2: putfield      #1                  // Field this$0:Lcom/test18/Outer;
         5: aload_0
         6: iconst_2
         7: anewarray     #2                  // class java/lang/String
        10: dup
        11: iconst_0
        12: ldc           #3                  // String a
        14: aastore
        15: dup
        16: iconst_1
        17: ldc           #4                  // String b
        19: aastore
        20: aconst_null
        21: invokespecial #5                  // Method com/test18/Outer."<init>":([Ljava/lang/String;Lcom/test18/Outer$1;)V
        24: return
      LineNumberTable:
        line 10: 0
        line 11: 5
        line 12: 24
}

  

 

  

以上是关于解语法糖之私有构造函数的主要内容,如果未能解决你的问题,请参考以下文章

Javac语法糖之增强for循环

私有类语法中的复制构造函数

Javac语法糖之TryCatchFinally

Javac语法糖之EnumSwitch

Java语法糖之泛型与类型擦除

vue3-setup语法糖之组件传参(definePropsdefineEmitsdefineExpose)