Signature----reproduced in Java

Source: Internet
Author: User

These days do not know how, always encountered a variety of nosuchmethodexception anomalies, but Java for the convenience of the value of the method to give our method signature, which for the first contact of the program ape seems a bit of egg pain. Today from the online good Baidu/google a bit, combined with their own knowledge, will now be related to the method signature information recorded, for later use.

First of all, to introduce what is the method signature, speaking of the method signature, we have to mention the Java method overload, referring to the method overload will have to mention the object-oriented polymorphism, OK, this is just said. Method signatures, as the name implies, method signatures, to distinguish between different methods of identifiers. We all know that the methods in Java must depend on the class, and the method is composed of the method name, the parameter list, the return value, and the method body.

In fact, the meaning of the method signature is not very great for different classes and different names of the same name, but for the overloaded method, the meaning of the method signature is very great. Because the method names between overloaded methods are the same, we are bound to find another feature and method name from the other elements of the composition method to form a signature that uniquely identifies the method, and the method body is certainly not considered. That is the formal parameter list and the return value, but because for the person calling the method, the shape of the method is much more important than the return value, so the method signature is composed of the method name + formal parameter list, that is, the method name and shape parameters according to the type list can only determine a method, There is no relationship to the return value of the method, which is an important basis for judging overloading, so the following code is not allowed.

[Java]View PlainCopy  
    1. Public Long AAAA () {
    2. }
    3. public int aaaa () {
    4. }

Next, let's explain what the JVM's exception information is meant to be when the program appears nosuchmethodexception. First we look at a few 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 of the small rules:

The method signature provided to us by the JVM is actually composed of the method name (the example above for simply not writing out the full class name), the formal parameter list, the return value three parts, the basic form is:

Full class name. Method name (form parameter by Type list) return value data type

We know that the structure of the method signature provided by the JVM is not enough, since the JVM does not specifically write out the data type, but rather provides a special notation, the following table is the relationship between the special representation character, the letter and the corresponding data type:

special character/letter meanings in Java method signatures
Special characters Data type Special Instructions
V void Typically used to represent the return value of a method
Z Boolean
B Byte
C Char
S Short
I Int
J Long
F Float
D Double
[ Array With [Start, with other special characters, representing the corresponding data type of the array, a few [represent a few dimensional array
L full class name; Reference type Start with L, end, middle is the full class name of the reference type


The above is a small explanation of the method signature and the method overload. It is important to note that when method overloading, the method return value has no meaning and is determined by the method name and the parameter list.

Signature----reproduced in Java

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.