is there a way if repeat is "false", then i dont want to use repeat and repeatMode anymore ? Instead of Overload, Can method ignore those params ?
void task(String title,boolean repeat, String repeatMode){
}
is there a way if repeat is "false", then i dont want to use repeat and repeatMode anymore ? Instead of Overload, Can method ignore those params ?
void task(String title,boolean repeat, String repeatMode){
}
I think you are finding something different: overload. This is when you have two or more methods with the same name and return type, but different arguments. Then, you can have:
void task(String title){
// do something
}
void task(String title, repeatMode){
// do something and repeat in some monner
}
and somewhere when you know if repeat
is true or not
if(repeat){
task(title);
}else{
task(title, repeatMode);
}
I believe something like this should be the structuring of the code, based on what else you have been asking:
void someMethodThatCallsTheOtherMethods() {
boolean repeat = true; //or false, whatever it should be
String title = "SomeTitle";
String repeatMode = "SomeValue";
if(repeat) {
task(title, repeatMode);
} else {
task(title);
}
}
void task(String title) {
//Do something with title alone
}
void task(String title, String repeatMode) {
//Do something with title and repeatMode
}
The check for which parameters to use for a method should be checked before the actual method call. You cannot determine that during the method call itself, so use a logic branch to determine that before the method call.