Is there a way to compute a Java class's method's signature? A signature
like ([Ljava/lang/String;)V
represents a function that takes a String[]
as argument
and returns void
.
What's the rule to compute the signature?
The method signature in java is defined as the structure of the method that is designed by the programmer. The method signature is the combination of the method name and the parameter list. The method signature depicts the behavior of the method i.e types of values of the method, return type of the method, etc.
A function's signature includes the function's name and the number, order and type of its formal parameters. Two overloaded functions must not have the same signature. The return value is not part of a function's signature.
A signature is a list that specifies a class constructor, an instance method, or a static method, thereby distinguishing it from other constructors, instance methods, or static methods.
It's always a set of parentheses enclosing type signifiers for the arguments, one after the other with no commas or anything, followed by a type signifier for the return value after the closing paren. It's pretty straightforward.
There's a table of type signatures on this page:
Signature Java Type Z boolean B byte C char S short I int J long F float D double V void L fully-qualified-class ; fully-qualified-class [ type type[]
Those last two mean that to name a class, you say, for example, Ljava/lang/Object;
, and to name an array of (for example) int
, you say [I
, and an array of array of int
is [[I
.
If you wanted to literally compute the signature in Java code based on reflection, it'd be simple enough; just use the table above with rules for handling objects and arrays.
Just run javap -s <class-name>
in the folder containing the .class
files . It will tell you with 100% accuracy. No need to guess these things.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With