我正在用java寫wicket的登錄頁面,並且希望儘可能將其寫入一般,所以我需要傳遞一個函數,這個函數在C++中被稱爲函數指針。 類是:Java中的函數指針
class LoginForm extends Form
{
public LoginForm(String id,TextField username,TextField password,WebResponse webResponse)
{
super(id);
}
@Override
public void onSubmit()
{
String password = Login.this.getPassword();
String userId = Login.this.getUserId();
String role = authenticate(userId, password);
if (role != null)
{
if (Login.this.getSave())
{
utilities.CreateCookie("Username", userId, false, 1209600, (WebResponse) getRequestCycle().getResponse());
utilities.CreateCookie("Password", password, false, 1209600, (WebResponse) getRequestCycle().getResponse());
}
User loggedInUser = new User(userId, role);
WiaSession session = (WiaSession) getSession();
session.setUser(loggedInUser);
if (!continueToOriginalDestination())
{
setResponsePage(UserHome.class);
}
}
else
{
wrongUserPass.setVisible(true);
}
}
}
其中身份驗證是功能怎麼辦?
[Java中函數指針最接近的替代物是什麼?]的可能重複(http://stackoverflow.com/questions/122407/whats-the-nearest-substitute-for-a-function-pointer-in- java) – Raedwald 2013-02-25 13:33:54