aspose file tools*
The moose likes Java in General and the fly likes why same method names in method overloading ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "why same method names in method overloading ?" Watch "why same method names in method overloading ?" New topic

why same method names in method overloading ?

anish jain
Ranch Hand

Joined: Feb 03, 2010
Posts: 129
In method overloading, what is the advantage of using same method names other than readability ?
Sona Patel
Ranch Hand

Joined: Mar 30, 2009
Posts: 75
whole point of method overloading is in keeping same name. If method name is same then we can call a single method and pass different types of values at runtime and JVM will take care of which method to call.
If method names are different then we have to decide which method to call for which type of value.

Hope it helps...
Rob Spoor

Joined: Oct 27, 2005
Posts: 19672

Start programming in C (which does not know function overloading) and ask again

Readability is the only answer. If method overloading would not be possible, you would get the following (taken from the GTK+ C API):
If you allow method / function overloading you can get rid of all those "_from_XXX" parts:
I surely would prefer the second set of functions.

How To Ask Questions How To Answer Questions
subject: why same method names in method overloading ?