Is it possible to have two methods with the same name but different parameters and return types in Java? Seems like it would be a good way to generalize a simple getter and setter.. You can do that with constructors why not with regular methods ? for example
why not be able to do ..
int getVal() {
return int;
}
boolean getVal() {
return true;
}
setVal(int a) {
}
and
setVal(boolean a) {
}
解决方案
Because then the compiler would be unable to figure out:
setVal(getVal());
should it call the bool or int version?