d2jsp
Log InRegister
d2jsp Forums > Off-Topic > Computers & IT > Programming & Development > Java, Method Overloading?
Add Reply New Topic New Poll
Member
Posts: 34,549
Joined: Mar 25 2009
Gold: 12,633.00
Aug 28 2018 11:10pm
I know you can change the parameter type and name, but is this ill advised?
also, pretty sure you can't change the return type of method?

Member
Posts: 12,786
Joined: May 17 2013
Gold: 4,010.00
Aug 29 2018 05:32am
Method overloading is a type of polymorphism. It makes no sense to have a different return type, since the method signature would be completely different.

Overloading is perfectly fine to use, as long as the methods are semantically equivalent. Basically you don't want the overloaded method to do a subtraction, with one version doing addition.

e.g., don't do this:

Code
public int sum(int a, int b){
return a+b;
}

public double sum(double a, double b){
return a-b;
}


This post was edited by Klexmoo on Aug 29 2018 05:34am
Member
Posts: 11,273
Joined: Apr 26 2008
Gold: 3,303.50
Aug 31 2018 11:42am
just create another method with a new name if you dont want the same stuff as the method you are planning to overload
Go Back To Programming & Development Topic List
Add Reply New Topic New Poll