On Tue, Aug 11, 2009 at 10:44 AM, Jörn Kottmann<kottm...@gmail.com> wrote: > Adam Lally wrote: >> > Lets say we have an interface Box{Number getNumber()} > then we could have a class BoxImpl implements Box{Integer getNumber(){...}}. > > Now I only would have to cast once > Box box = ...; > BoxImpl boxImpl = (BoxImpl) box; > > now > Integer number = boxImpl.getNumber() > would work. Sure if you do the same for CAS and CASImpl > you safe lots of casts. > > The same does not work for a getNumbers which > returns a List<Number> or Iterator<Number> > without also allowing down casting. >
Well, true, but it does not really create an analogous solution if you do: interface Box{List<T extends Number> getNumberList()} class BoxImpl{List<Integer> numberList()} Because a client could call List<Integer> x = box.getNumberList() whether or not box was actually a BoxImpl. -Adam