It's true that it will eliminate the need for a cast, but the API is not 
pretty, and you still won't catch errors until runtime. If we really think that 
casting is a big deal (which I'm not sure I do), I'd much prefer adding a type 
parameter to the methods.
G

On Jan 25, 2011, at 3:01 PM, calathus wrote:

> 
> 
> On Tue, Jan 25, 2011 at 11:42 AM, Greg Brown <[email protected]> wrote:
> > Since generic version may give wrong impression that it is type safe, it 
> > may be better to provide two version for getter, one is just return 
> > List<object>, another will return List<T> taking class value as the 
> > argument. also we may use generic method for setter. see following sample 
> > code.
> ...
> >         public List<Object> getList() {
> >             return (List<Object>)ts;
> >         }
> >         public <T> List<T> getList(Class<T> cls) {
> >             return (List<T>)ts;
> >         }
> 
> Yuck. I think it is probably best to leave it as-is.
> 
> I think this approach will eliminate using cast for adding element(which is 
> very frequently used), while current one still requires cast.
> And I think most of case, the second case won't be required.
> 
>  
> 
> 
> 
> -- 
> Cheers,
> calathus
> 
> 
> 

Reply via email to