ClassのSignatureプロパティについて

5775 ワード


1、Signature属性:https://docs.oracle.com/javase/specs/jvms/se7/html/jvms-4.html#jvms-4.7.9
2、ClassSignature、FieldType Signature、MethodType Signatureの説明:
https://docs.oracle.com/javase/specs/jvms/se7/html/jvms-4.html#jvms-4.3.2-200
3、JLS:https://docs.oracle.com/javase/specs/index.html
例を挙げると、次のようになります.
interface IA{}
interface IB{}

class CA{}

class TP extends CA implements IA,IB{}

class ParentClass{}

interface ParentIA{}
interface ParentIB{}

//  ClassFile attributes Signature 
// 
// Lcom/test18/ParentClass;
// Lcom/test18/ParentIA;Lcom/test18/ParentIB;
public class TestClass
        extends ParentClass
        implements ParentIA,ParentIB{


	//  methods attributes Signature 
	// 
	// (TA;Ljava/util/List;)
	// V
    public void mymethod(A a,List extends B> list){
// プールにしか れませんが、なぜですか?
// Ljava/util/List;
List  x = null;
// Ljava/util/List;
List super InputStream> y = null;
} 
}

Javap-verbose TestClassでClassファイルの構造を表示するには、次の手順に従います.
Classfile /C:/TestClass.class
  Last modified 2018-7-5; size 1058 bytes
  MD5 checksum d9dc89733c2ea9a57bbced4b4c20f998
  Compiled from "TestClass.java"
public class com.test18.TestClass extends com.test18.ParentClass implements com.test18.ParentIA, com.test18.ParentIB
  Signature: #29                          // Lcom/test18/ParentClass;Lcom/test18/ParentIA;Lcom/test18/ParentIB;
  SourceFile: "TestClass.java"
  minor version: 0
  major version: 51
  flags: ACC_PUBLIC, ACC_SUPER
Constant pool:
   #1 = Methodref          #3.#32         //  com/test18/ParentClass."":()V
   #2 = Class              #33            //  com/test18/TestClass
   #3 = Class              #34            //  com/test18/ParentClass
   #4 = Class              #35            //  com/test18/ParentIA
   #5 = Class              #36            //  com/test18/ParentIB
   #6 = Utf8               
   #7 = Utf8               ()V
   #8 = Utf8               Code
   #9 = Utf8               LineNumberTable
  #10 = Utf8               LocalVariableTable
  #11 = Utf8               this
  #12 = Utf8               Lcom/test18/TestClass;
  #13 = Utf8               LocalVariableTypeTable
  #14 = Utf8               Lcom/test18/TestClass;
  #15 = Utf8               mymethod
  #16 = Utf8               (Lcom/test18/CA;Ljava/util/List;)V
  #17 = Utf8               a
  #18 = Utf8               Lcom/test18/CA;
  #19 = Utf8               list
  #20 = Utf8               Ljava/util/List;
  #21 = Utf8               x
  #22 = Utf8               y
  #23 = Utf8               TA;
  #24 = Utf8               Ljava/util/List;
  #25 = Utf8               Ljava/util/List;
  #26 = Utf8               Ljava/util/List;
  #27 = Utf8               Signature
  #28 = Utf8               (TA;Ljava/util/List;)V
  #29 = Utf8               Lcom/test18/ParentClass;Lcom/test18/ParentIA;Lcom/test18/ParentIB;
  #30 = Utf8               SourceFile
  #31 = Utf8               TestClass.java
  #32 = NameAndType        #6:#7          //  "":()V
  #33 = Utf8               com/test18/TestClass
  #34 = Utf8               com/test18/ParentClass
  #35 = Utf8               com/test18/ParentIA
  #36 = Utf8               com/test18/ParentIB
{
  public com.test18.TestClass();
    flags: ACC_PUBLIC
    Code:
      stack=1, locals=1, args_size=1
         0: aload_0
         1: invokespecial #1                  // Method com/test18/ParentClass."":()V
         4: return
      LineNumberTable:
        line 53: 0
      LocalVariableTable:
        Start  Length  Slot  Name   Signature
               0       5     0  this   Lcom/test18/TestClass;
      LocalVariableTypeTable:
        Start  Length  Slot  Name   Signature
            0       5     0  this   Lcom/test18/TestClass;

  public void mymethod(A, java.util.List extends B>);
flags: ACC_PUBLIC
Code:
stack=1, locals=5, args_size=3
0: aconst_null
1: astore_3
2: aconst_null
3: astore        4
5: return
LineNumberTable:
line 60: 0
line 61: 2
line 62: 5
LocalVariableTable:
Start  Length  Slot  Name   Signature
0       6     0  this   Lcom/test18/TestClass;
0       6     1     a   Lcom/test18/CA;
0       6     2  list   Ljava/util/List;
2       4     3     x   Ljava/util/List;
5       1     4     y   Ljava/util/List;
LocalVariableTypeTable:
Start  Length  Slot  Name   Signature
0       6     0  this   Lcom/test18/TestClass;
0       6     1     a   TA;
0       6     2  list   Ljava/util/List;
2       4     3     x   Ljava/util/List;
5       1     4     y   Ljava/util/List;
Signature: #28                          // (TA;Ljava/util/List;)V
}