Hi!

Yes.. this is true but not ideally consistent. More consistent would be

DropDownChoice<? extends BaseClass> dropDown = new DropDownChoice<?
extends BaseClass>("id");

in such a way that dropDown.getChoiceRenderer() would be automatically
of type <BaseClass>.

One solution would be to change the signature of DropDownChoice (and
selectchoices ...):

public class DropDownChoice<T> extends .... into

public class DropDownChoice<T, S extends T> extends .... in such a manner that

DropDownChoice<? extends BaseClass=T> dropDown = new DropDownChoice<?
extends BaseClass=T>("id");
and

DropDownChoice.getChoiceRenderer() : S

That would work... both ways?

**
Martin

2009/6/13 James Carman <jcar...@carmanconsulting.com>:
> No casting is required.  Try this:
>
> BaseClass baseObject = null;
> DropDownChoice<BaseClass> dropDown = new DropDownChoice<BaseClass>("id");
> dropDown.getChoiceRenderer().getDisplayValue(null);
>
> This will compile (it won't run because you'll get an NPE if the
> display value method doesn't accept null).  As I said, you don't have
> to declare your local variable "dropDown" with type variable
> wildcards.
>
>
>
> On Sat, Jun 13, 2009 at 6:23 AM, Martin
> Makundi<martin.maku...@koodaripalvelut.com> wrote:
>> No. The compiler does not allow. If DropDownChoice is of type <?
>> extends BaseClass> then the problem is that it assumes that
>> getChoiceRenderer() is also of type <? extends BaseClass>. Now at
>> runtime, because of the wildcard, I do not know what class I have, and
>> I absolutely cannot use the renderer. The only workaround is to cast
>> the renderer into <BaseClass> (which it actually is!!) and that works,
>> but the warning remains.
>>
>> Tricky....
>>
>> **
>> Martin
>>
>> 2009/6/13 James Carman <jcar...@carmanconsulting.com>:
>>> But, the compiler only knows what you're allowed to do by the type of
>>> the variable.  You do not need to declare your variables with the
>>> wildcards.
>>>
>>> On Fri, Jun 12, 2009 at 6:31 PM, Cristi Manole<cristiman...@gmail.com> 
>>> wrote:
>>>> declaration is not the problem. from what i remember from generics (I might
>>>> be wrong), you're not allowed to instantiate "generically". you have to 
>>>> tell
>>>> the compiler exactly what type you want. at runtime it has no idea about
>>>> generics.
>>>>
>>>> On Sat, Jun 13, 2009 at 12:41 AM, James Carman
>>>> <ja...@carmanconsulting.com>wrote:
>>>>
>>>>> Just because the constructor is declared that way (with the ?) doesn't 
>>>>> mean
>>>>> you have to declare your variables that way.
>>>>>
>>>>> On Jun 12, 2009 4:43 PM, "Martin Makundi" <
>>>>> martin.maku...@koodaripalvelut.com> wrote:
>>>>>
>>>>> > new DropDownChoice<BaseClass> ?
>>>>>
>>>>> Maybe ...
>>>>>
>>>>> **
>>>>> Martin
>>>>>
>>>>> > > On Fri, Jun 12, 2009 at 6:06 AM, Martin > Makundi<
>>>>> martin.maku...@koodaripalvelut.com> wrote: >>...
>>>>>
>>>>
>>>>
>>>>
>>>> --
>>>> Cristi Manole
>>>>
>>>> Nova Creator Software
>>>> www.novacreator.com
>>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
>>> For additional commands, e-mail: users-h...@wicket.apache.org
>>>
>>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
>> For additional commands, e-mail: users-h...@wicket.apache.org
>>
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
> For additional commands, e-mail: users-h...@wicket.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org

Reply via email to