What is the difference between "descriptor" and "signature"?

akry picture akry · Sep 23, 2011 · Viewed 7.9k times · Source

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"?

Answer

James Moore picture James Moore · Nov 6, 2012

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;>;>;