In Java, a method signature is part of the method declaration. It's the combination of the method name and the parameter list.

在Java中 ,方法签名是方法声明的一部分。 它是方法名称和参数列表的组合。

The reason for the emphasis on just the method name and parameter list is because of overloading. It's the ability to write methods that have the same name but accept different parameters. The Java compiler is able to discern the difference between the methods through their method signatures.

只强调方法名称和参数列表的原因是由于重载 。 可以编写名称相同但接受不同参数的方法。 Java编译器能够通过它们的方法签名来识别方法之间的差异。

方法签名示例 ( Method Signature Examples )


public void setMapReference(int xCoordinate, int yCoordinate){//method code}

The method signature in the above example is setMapReference(int, int). In other words, it's the method name and the parameter list of two integers.

上例中的方法签名为setMapReference(int,int)。 换句话说,它是方法名称和两个整数的参数列表。


public void setMapReference(Point position){//method code}

The Java compiler will let us add another method like the above example because its method signature is different, setMapReference(Point) in this case.

Java编译器将让我们添加与上述示例类似的另一个方法,因为它的方法签名不同,在这种情况下为setMapReference(Point)


public double calculateAnswer(double wingSpan, int numberOfEngines, double length, double grossTons) {   //method code}

In our last example of a Java method signature, if you follow the same rules as the first two examples, you can see that the method signature here is calculateAnswer(double, int, double, double).

在我们的Java方法签名的最后一个示例中,如果遵循与前两个示例相同的规则,则可以看到此处的方法签名为calculateAnswer(double,int,double,double)

翻译自: https://www.thoughtco.com/method-signature-2034235

Java方法签名的定义相关推荐

  1. java 方法里面定义接口_java – 当接口A在其方法签名中定义接口B时

    -如何限制A的实现在方法签名中使用B的某个实现? 用例 这是一个Unit接口和两个实现它的枚举: public interface Unit { ... } public enum ForceUnit ...

  2. java 接口 签名机制_java – 当接口A在其方法签名中定义接口B时

    -如何限制A的实现在方法签名中使用B的某个实现? 用例 这是一个Unit接口和两个实现它的枚举: public interface Unit { ... } public enum ForceUnit ...

  3. Java方法签名格式

    1. 格式 Java的方法签名格式: modifiers type name (paramlist) [ throws exceptions ] 2. 相关说明 2.1 modifiers 零个或多个 ...

  4. Thinking in Java方法签名

    方法名和参数(即,方法签名)唯一标识某个方法:如, public void add(int a,int b){ } //这两个方法的方法签名一样,是不能在同一.java里的,编译通不过 public ...

  5. Java中的方法签名

    这几天不知道怎么了,总是碰到各种各样的NoSuchMethodException异常,但是Java为了方便值给了我们方法的方法签名,这对于刚接触的程序猿来说貌似有点蛋疼.今天从网上好好的百度/goog ...

  6. java方法_Java方法

    java方法 Java is an Object Oriented Programming language. Java Methods are defined in the class and th ...

  7. 学JNI之方法签名遇到的问题

    在学习JNI中寻找方法签名时遇见的问题 1.when 在学习安卓JNI时,c调java中的方法时用到方法 env->GetMethodID(jclazz,"add1", &q ...

  8. java对于数组的定义_Java中方法的定义与使用,以及对数组的初步了解。

    方法 方法的含义 定义: 方法就是用来完成解决某件事情或实现某个功能的办法. 方法实现的过程中,会包含很多条语句用于完成某些有意义的功能--通常是处理文本,控制输入或计算数值. 我们可以通过在程序代码 ...

  9. Java中方法签名signature、方法重载以及“两同两小一大”的方法覆盖(方法重写)总结

    1. 方法 1.1 方法 实现了某一功能,代码可以复用 1.2 方法签名 java中每个方法都有一个签名,包含方法名和参数列表(类型.个数以及顺序),只要其中一个不同,方法的签名不同,也就是属于不同的 ...

最新文章

  1. ANSYS报错Accelerations are exceeding internal limit解决方法
  2. Kong APIGW — Plugins — Authentication
  3. 判断字符串_python实现--判断回文字符串、回文链表、回文数
  4. 如何查询MySql日志
  5. bike with a famous logo
  6. 影响 PCR 体系蒸发的三大因素
  7. 线索化二叉树(代码 、分析 、汇编)
  8. 第十七期:2019人工智能统计数字和一些重要事实
  9. python 随机_python1到3秒随机延时入坑python 心情舒畅
  10. 韩国有多大?相当于中国哪里?
  11. struct与class的区别
  12. NovelAI-WebUI安装教程
  13. a标签去掉下划线以及字体颜色
  14. vios aix_为AIX或VIOS选择多路径路径控制模块的指南
  15. 盘点那些大学生自习室最无法忍受的行为!
  16. 2019年2月18日,异常作业
  17. 在 VMware vSphere 中构建 Kubernetes 存储环境
  18. 计算机程序设计在日常生活中的应用,《走进程序设计》教学设计
  19. 大数据量的五种处理方式
  20. PAC文件解释-转载 小胡子哥的个人网站

热门文章

  1. crypto buuctf rabbit
  2. 三星a5100多少钱_请问三星A5100现在啥价格?
  3. 线程进程计算之多任务同步进行
  4. 写于数学建模美赛准备期间
  5. 计算机打字大赛策划书,打字比赛策划书
  6. PAP和CHAP协议介绍
  7. python对红楼梦的每一章节进行词频统计
  8. 【数据结构】无向图与有向图的连通性及相关算法
  9. 4.Python数据容器之字符串(str)
  10. (一)1.线性规划 之 化标准型和图解法