Same named methods in Java. Part 1: Don’t Underestimate Overloading
dev.to·11h·
Discuss: DEV

Recently I posted a poll on LinkedIn about method selection in overloaded method calls and was rather surprised that only 20% of the answers were correct. That gave me a push to do this write-up, as I feel that same-named methods do not get the credit they deserve for the mess they can cause.

I plan to make this a three-part article. This part will look purely at method overloading within a single type definition (class, interface, or enum). Basically, we going to look into how most specific method is selected by only looking at methods arguments. Part two will cover overloading with generics. Part three will examine the complexities beyond the single-type case, such as inheritance, polymorphism, and method hiding.

Throughout this article, I am not going to get into the differen…

Similar Posts

Loading similar posts...