On Mon, Jan 24, 2011 at 4:51 PM, calathus <[email protected]> wrote:
> > > On Mon, Jan 24, 2011 at 2:41 PM, Greg Brown <[email protected]> wrote: > >> > main advantage is the ability to assign to List<J> variable. >> >> Not sure I see the distinction - the same thing applies to >> setListData(List<?>). >> > > I was mentioning the getter operator, not setter. > The direction of assignment is important. > setter's parameter type is sort of lift hand side while getter return type > come to right hand side. > > In this sense, the use of anonymous type in setter argument is less > problematic. > > The advantage over List<Object> is the ability to assigned the ability to > just any List<N>. > If we use List<Object> we need to copy another object just overcome this > issue. If we need to maintain object identity, this approach is not > appropriate. Then we will be stuck. > If it returns List<object>, if we use double cast, it can still convert to List<Object> without losing object identity. List<Object> list4 = (List<Object>)(Object)a.getList1();// getList1 returns List<Object> But who would like to write such code? > > >> >> > if we use List<?> as the return type, this can be done with cast, but if >> we use List<Object> as return type, cast cannot be applied also. >> >> Right, I had forgotten about that. That's why it currently returns >> List<?>. Returning List<T> would simply make the cast unnecessary. > > > > > -- > Cheers, > calathus > > > > -- Cheers, calathus
