Why is the BookmarkablePageLink class generic in Wicket?
Does anyone know why the BookmarkablePageLink
clas开发者_Go百科s is generic in wicket? I have been creating new BookmarkablePageLink<Object>(...)
just to avoid the compiler warnings.
Should I be choosing a different generic type? A brief view of the code just confused me further about why it was generic.
When Wicket 1.4 was introduced, the developers decided to generify the Component
class. Since BookmarkablePageLink
is a descendent of Component
(like pretty much everything in Wicket), it became generic as well.
The Wicket 1.4 migration guide recommends using Void
as the generic type for BookmarkablePageLink
s, as well as other Wicket components that generic types don't really make sense for.
From a brief overview of the javadoc it looks like the reason for generics can be seen in the abstract superclass Link. Specifically, a Link lets you associate with it a model object of a generic type via setModelObject. So from their example, when you override onClick:
new Link<MyObject>("myLink") {
public void onClick()
{
MyObject obj = getModelObject();
setResponsePage(new MyPage(obj));
}
}
You can access a relevant model object.
精彩评论