楼主:
edash (团长)
2016-03-14 02:34:49各位板友好
目前在学习 method overloading,已经了解到不同 method 要 overloading 的前提是:
1. method的名称要相同
2. 参数的型别顺序或种类不同
另外,看到一句话有点不解
Internally, the compiler uses longer method names that include
the original method name,
the types of each parameter and the exact order of the parameters
to determine whether the methods in a class are unique in that class.
解读这句话的意思是:
编译器实际的作法,是用较长的 method 签名,来判定
类别中的其余 method 是否为唯一。
但还是想多了解一些细节
我可以理解,不管程式中有无呼叫这些 overloaded method,编译器也应该会去
比较不同 method,来确定类别中一定不会发生两个以上的 method 有着相同签名
但所谓的“longer”的意思是,有着较多参数的 method 吗?
如果有板友能再多解释一下编译器的实际判定作法就太好了
谢谢~
作者:
LPH66 (-6.2598534e+18f)
2016-03-14 03:32:00你(或者是教材)或许把 overload 跟 override 搞混了这里讲的东西比较接是 override, 继承时有没有覆蓋父类方法接近*overload 则只单纯是同名, 而且正是以参数的不同做为分别至于所谓的较长 method 签名, 各语言或各编译器有不同做法java 的做法是把参数型态和回传值编码成一个字串使用这字串和函数名共两个字串做一组来看其他语言有把这两个字串给编码在一起成一个字串的 (如 C++)一般这类的编码规则会叫做 name-mangling