Re: what is encapsulation  in an interface ?
 
Ken Wesson wrote:
(In reality there's not much reason to have multiple implementations of
countNonNulls; *obviously* it'll be "int i = 0; for (Object o : x) if (o ! =
null) i++; return i;". :) But it serves as a quick example.)
Tom Anderson wrote:
Ahem:
return x.size() - Collections.frequency(x, null);
tom highlights a very important and, at least by me, all-too-overlooked 
phenomenon, to whit, the ongoing development of the collections framework.
So much stuff has been added since Java 5 (such as the cited 
'Collections.frequency()') and since 6 that really simplifies and enhances 
coding power and expressiveness.  A colleague at work was just waxing 
rhapsodic yesterday about the power of the 'Set' interface.  ('retainAll()' 
was the specific focus of his adoration, which actually has been around for a 
long time.  Somehow his predecessor maintainers of that particular module had 
missed it, though, and hadn't really done a very good job of reinventing it, 
either.)
They don't make as much fanfare about the work on collections as about other 
areas (generics, for example, which are largely motivated by their 
potentiation of collections), but it's arguably some of the most significant 
improvement to the Java platform.
It pays to review the collections API frequently for such gems.
It also pays to be sensitive to when "obvious" is actually a reflection of 
dogma or habit.
-- 
Lew
Ceci n'est pas une pipe.