What is a method signature? [duplicate]

≡放荡痞女 提交于 2019-12-13 10:53:56

问题


I read a book titled 'Object First with Java' and in page 7 the author mentioned that the method signature "provides information needed to invoke that method". And the the author gave the following example:

void moveHorizontal(int distance)

However, today when I was watching a video about C# on Pluralsight, the author said that "the return type of a method is not part of the method signature".

I'm confused now and would like know what is a method signature?


回答1:


A method-signature is the part of the method based on which you overload / override it. It contains :

  1. The method name.
  2. The arguments passed to it.

It doesn't contain :

  1. Scope / access modifier
  2. return type.



回答2:


Method signature is used in interfaces and in abstract classes, but we always define the method data type(return type). It will be something invaluable if the return type is not a part of the signature.



来源:https://stackoverflow.com/questions/29672548/what-is-a-method-signature

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!