Current location - Quotes Website - Signature design - What is method signature in JAVA?
What is method signature in JAVA?
In fact, for methods with the same name, different classes and different names, method signature is of little significance, but for overloaded methods, method signature is of great significance. Because the method names between overloaded methods are the same, we must find another element and method name from several other elements that make up the method to form a signature that can uniquely mark the method, and the method body is definitely not considered. Then the formal parameter table and the return value, but for the caller, the formal parameter table of the method is much more important than the return value, so the method signature is composed of the method name and formal parameter table, which means that the method name and formal parameter table can uniquely determine a method, regardless of the return value of the method, which is an important basis for judging overloading, so the following code is not allowed.

Public long aaaa(){

}

public int aaaa(){

}

Next, let's explain what the exception information provided by JVM means when the program has a NoSuchMethodException. First, let's look at several methods and their method signatures:

Public void test1() {} test1() v.

public void test2(String str)test2(Ljava/lang/String; )V

public int test3(){} test3()I

From the above three examples, we can easily see some small laws:

The method signature provided by JVM actually consists of three parts: the method name (the above example did not write the complete class name for simplicity), the parameter table and the return value. The basic form is:

The full class name. Method name (list of formal parameter data types) returns the data type.

After we know the structure of the method signature provided by the JVM, this is not enough, because the JVM does not specifically write the data type, but provides a special representation. The following table shows the relationship between special presentation characters and letters and the corresponding data types:

Special Character/Letter Meaning in Java Method Signature

Special description of special character data types

Vvoid is usually used to represent the return value of a method.

Zboolean

Bbyte

Cahal

short

Iint

Jinlong

Ffloat

double

[Arrays begin with [,and cooperate with other special characters to represent arrays of corresponding data types, and several [arrays representing several dimensions.

L complete class name; The reference type starts with l,; Finally, in the middle is the full class name of the reference type.