Helper classes

Stephen Colebourne scolebourne at joda.org
Mon Apr 15 14:54:50 PDT 2013


On 15 April 2013 22:41, Brian Goetz <brian.goetz at oracle.com> wrote:
> An example of a method at the other end of the spectrum is
> Collections.rotate(List, int).  Sure, this is useful when you need it,
> but it just isn't that important, and weighing down an interface with
> 5000 lines of additional code (OK, Collections is only 4700 LoC) really
> clogs up the Collection interface.

Perhaps there is a semblance of a first rule here.

- Collections.rotate(List, int)  - static
could now be:
- List.rotate(List, int)  - static
but that would just look and behave weirdly, because it should be
- List.rotate(int)  - instance

But, most of us would agree that an instance method for rotating
probably isn't justified. Thus it is also not justified as a static
method on the same interface.

The rule is therefore along the lines of "don't add a static method
where one of its arguments is the same type as the interface and the
methods purpose is to operate on that argument. Either use a default
instance method on the interface, or keep it in a separate utility
class".

Stephen


More information about the lambda-dev mailing list