Just exploring this a bit deeper ... these all end up doing the same thing.
final Link<?> link = new BookmarkablePageLink<Void>("a-title",
Home.class);
this.add(link);
final IModel<?> m = link.getModel();
final Object o = m.getObject();
final Link<Void> link = new BookmarkablePageLink<Void>("a-title",
Home.class);
this.add(link);
final IModel<Void> m = link.getModel();
final Object o = m.getObject();
final Link<Void> link = new BookmarkablePageLink<Void>("a-title",
Home.class);
this.add(link);
final IModel<?> m = link.getModel();
final Object o = m.getObject();
This breaks for obvious reasons:
final Link<?> link = new BookmarkablePageLink<Void>("a-title",
Home.class);
this.add(link);
final IModel<Void> m = link.getModel();
final Object o = m.getObject();
But this DOES work (incorrectly with respect to intent):
final Link<?> link = new BookmarkablePageLink<String>("a-title",
Home.class);
this.add(link);
*final IModel<String> m = (IModel<String>) link.getModel();*
final Object o = m.getObject();
And this is broken (correctly - it doesn't compile):
final Link<Void> link = new BookmarkablePageLink<Void>("a-title",
Home.class);
this.add(link);
final IModel<String> m = (IModel<String>) link.getModel();
final Object o = m.getObject();
Using <?> allows me to cast the model. Using <Void> does not allow me to
cast. Now that I understand the idea here, I think technically, Void is
probably a better choice here. Does that make sense Igor?
Implementation aside, conceptually and with respect to intent, I also think
<Void> seems a little more final and resolute - an explicit choice by the
developer -- whereas <?> seems to convey ... "ah, I need to keep my options
open :) Maybe I'll need to cast this later." Indeed, that is what prompted
me to do the test above.
For what its worth, I'd never seen <Void> before this thread. Thanks Igor
and James.
Thanks,
-Luther
Igor's perspective -
One 'self-documenting' part
On Mon, May 25, 2009 at 10:38 AM, Igor Vaynberg <[email protected]>wrote:
> no, you cannot instantiate <?>, but you can instantiate <Void> and
> assign it to <?> as per my example below
>
> -igor
>
> On Mon, May 25, 2009 at 6:05 AM, James Carman
> <[email protected]> wrote:
> > On Sun, May 24, 2009 at 11:16 PM, Igor Vaynberg <[email protected]>
> wrote:
> >> final Link<?> link = new BookmarkablePageLink<Void>("a-contact",
> >>
> >> if you are not intending on using the model use <?> which will help
> enforce that
> >
> > Care to elaborate on that? How does <?> assure that folks aren't
> > going to use the model better than <Void>? You can't instantiate a
> > BookmarkablePageLink<?>.
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: [email protected]
> > For additional commands, e-mail: [email protected]
> >
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
>
>