For faster navigation, this Iframe is preloading the Wikiwand page for 类型签名.

类型签名

电脑科学中,类型签名(英语:type signature)或类型注解type annotation)是对程序的函数、方法、子过程、以及变量等给出其类型。特别是对函数给出其输入参数数量、类型与次序及输出结果的类型。 许多编译器产生的内部使用的函数名包含了其类型特征,这称为名字修饰,为链接器辨别不同的函数提供了方便。[1]

类型特征的现代应用:

  • 面向对象语言使用的interface,实际上是利用了函数类型特征的模板。
  • C++支持的函数重载实际上用不同的类型特征来辨识。
  • 多继承要求考虑函数特征,以避免不可预计的结果。

C/C++

[编辑]

CC++ 中,类型签名通常被声明为函数原型,函数声明也反映了其用法。例如,函数指针使用方法如下:

char c;
double d;
int retVal = (*fPtr)(c, d);

它的签名为:

(int) (char, double);

Java

[编辑]

在Java中,方法签名(英语:method signature)由方法的名字(method's name)与参数类型(parameter types)组成。[2] 如下例:

public double calculateAnswer(double wingSpan, int numberOfEngines,
                              double length, double grossTons) {
    //do the calculation here
}

该例的方法签名为:calculateAnswer(double, int, double, double)

参考文献

[编辑]
  1. ^ C++ Reference: Programming terms. [3 December 2013]. (原始内容存档于2020-01-19). 
  2. ^ Defining Methods (The Java™ Tutorials > Learning the Java Language > Classes and Objects). docs.oracle.com. [2020-05-19]. (原始内容存档于2021-04-17). 
{{bottomLinkPreText}} {{bottomLinkText}}
类型签名
Listen to this article

This browser is not supported by Wikiwand :(
Wikiwand requires a browser with modern capabilities in order to provide you with the best reading experience.
Please download and use one of the following browsers:

This article was just edited, click to reload
This article has been deleted on Wikipedia (Why?)

Back to homepage

Please click Add in the dialog above
Please click Allow in the top-left corner,
then click Install Now in the dialog
Please click Open in the download dialog,
then click Install
Please click the "Downloads" icon in the Safari toolbar, open the first download in the list,
then click Install
{{::$root.activation.text}}

Install Wikiwand

Install on Chrome Install on Firefox
Don't forget to rate us

Tell your friends about Wikiwand!

Gmail Facebook Twitter Link

Enjoying Wikiwand?

Tell your friends and spread the love:
Share on Gmail Share on Facebook Share on Twitter Share on Buffer

Our magic isn't perfect

You can help our automatic cover photo selection by reporting an unsuitable photo.

This photo is visually disturbing This photo is not a good choice

Thank you for helping!


Your input will affect cover photo selection, along with input from other users.

X

Get ready for Wikiwand 2.0 🎉! the new version arrives on September 1st! Don't want to wait?