I have two methods like
public void login(String userName, String password)
{
}
public void login(String userName, String password, Object loginOption)
{
}
and I hope to get all of them soloved in a certain method:
public boolean getThingsDone(Object...vargs)
{
//Do The Real Action
return true;
}
so I have to make different function call:
public void login(String userName, String password)
{
getThingsDone(userName,password);
}
public void login(String userName, String password, Object loginOption)
{
getThingsDone(userName,password,loginOption);
}
Is there any way that I can put different parameter into one List, so I can make the same call
getThingsDone(parameterList);
I have no idea but declare both method into login(String …vargs), but that will confuse other people use this method.
Is there any one ever meet this problem? Any hint would be appreciated.
You can create a
Loginclass with three attributes: –username, password, loginOption.And in your login method pass
Loginreference as parameter: –So, if you want to pass
loginOptions, call it like this: –else, just use a
2-parameterized constructorofLoginclass: –And from login method, call other method like this: –
Now in that method, check : –
if (login.getLoginOptions() != null). If it is null, then do things related tousernameandpassword. And if it is not null, then do things related to all of them.