The following remarks for the novice opinion, if there is inappropriate, please advise.
Overloading is a function/method within a class that defines several identical names but different parameters. As follows:
1 classbasketballplayer{2 PrivateString sex;3 PrivateString name;4 Public voidTest (String name) {5 ......}6 Public voidTest (String name,string sex) {7 ......}8}
But I personally feel that sometimes this function is more chicken, I might as well as the following to write a simple and convenient, unfortunately, the following is not used in Java, but also in my regular use of C + + and PHP support:
1 class basketballplayer{2 Private String sex; 3 Private String name; 4 Public void Test (String name,string sex="man") {5 ......} 6 }
Of course overloaded it also has practical time, such as:
int themax (int A,int b) { return a>b? a:b;} float themax (floatfloat b) { return a>b a:b;}
But I still think this is not a good way, the same function is only different data types will be written so many times the logic is exactly the same thing, is a waste of physical strength Ah, to modify also have to change one by one, perhaps to change the leak. I think a weak data type (such as PHP) is a better solution, and it automatically helps you handle different data types. As follows:
1 <? PHP 2 function Themax ($a,$b) { //max is a system function is not available, so the name Themax3 return$a>$b$a$b; 4 }5 ?>
The current popular several strong-type language compiler will not, dare, would like to put "weak type" in it. It's hard to say, probably not for a long time. In particular, Java is more unlikely, some of the features are already there, it will be over n long, such as switch inside to put a string to the 1.7 version only. For now, the ultimate solution can only be used in weakly typed languages such as PHP,JS, and the strong type will have to suffer for a while in the reincarnation of copy-and-paste modification.
Overloading-object-oriented chicken ribs, strong-type language weakness