I am now using ASM (Java bytecode instrumentation library). To retrieve the signature of given method, there is a field which is named "desc". I guess this is an abbreviation of "descriptor", but why isn't it named as "signature"? Is there any difference between "descriptor" and "signature"?
Looking at the JVM spec section 4.3.3, for one thing the descriptor contains the return type - whereas that isn't part of a the signature of a method.
A method descriptor represents the parameters that the method takes and the value that it returns
but...
Two methods have the same signature if they have the same name and argument types
(Given this, it's also not clear that the descriptor contains the name of the method...)
In the context of asm, you care about internal names, method descriptors, type descriptors and signatures. Section numbers are from the asm doc.
2.1.2 Internal names
"The internal name of a class is just the fully qualified name of this class, where dots are replaced with slashes."
com/snark/Boojum
2.1.3 Type descriptors
[[Ljava/lang/Object;
2.1.4 Method descriptor
A method descriptor is a list of type descriptors that describe the parameter types and the return type of a method, in a single string.
int[] m(int i, String s) becomes (ILjava/lang/String;)[I
4.1. Generics (for signatures)
"For backward compatibility reasons the information about generic types is not stored in type or method descriptors (which were defined long before the introduction of generics in Java 5), but in similar constructs called type, method and class signatures."
This Java:
List<List<String>[]>
Becomes this signature:
Ljava/util/List<[Ljava/util/List<Ljava/lang/String;>;>;
Looking at the JVM spec section 4.3.3, for one thing the descriptor contains the return type - whereas that isn't part of a the signature of a method.
A method descriptor represents the parameters that the method takes and the value that it returns
but...
Two methods have the same signature if they have the same name and argument types
(Given this, it's also not clear that the descriptor contains the name of the method...)
"descriptor" probably refers to the method descriptor as defined in the JVM spec § 4.3.3. It describes the parameter types and the return type of a method. It does not contain the method name.
"signatur" probably refers to the signature of as defined in the Java Language Specification § 8.4.2. It contains the name of the method as well as the parameter types. It does not contain the return type.
Note that those two terms are defined in two different places and at different levels. A method descriptor exists at the JVM-level, so it's pretty detached from the Java language. The signature, however is a very similar concept, but acts on the Java language level (as it's defined in the JLS).
© 2022 - 2024 — McMap. All rights reserved.