Java: list-ops: include hints to explain why methods are static

Created on 8 Mar 2017  Â·  3Comments  Â·  Source: exercism/java

As per #177, we prefer using instance methods over class methods (see discussion in that issue for rationale).

However, there _are_ conditions in which it is absolutely appropriate for a function to be static. A common situation is because the function is effectively an extension of an existing type — you are defining behavior you wished were defined on a given type.

Since classes in Java are closed for modification (i.e. you cannot add members to a class outside its definition like you can in other languages like Ruby or JavaScript), you cannot add the new behavior to the class, directly. The idiomatic solution in this case is to write a utility method.

Collections of these kinds of methods are often referred to as "utility classes". Examples of such classes from within the JRE include Arrays and Collections.

In the case of the exercise list-ops, we "wish" that List had map(), reduce(), filter(), etc. methods on it. It doesn't, so we're including them here.

Please include a HINT.md file in list-ops that points out that these methods are static and capture the description above, in your own words as to why this class has this shaped API.

documentation good first issue hacktoberfest

All 3 comments

Would you mind if I claim this one?

Great, go for it! :)

@FridaTveit done, I hope it looks good 😄

Was this page helpful?
0 / 5 - 0 ratings

Related issues

dawcars picture dawcars  Â·  7Comments

ErikSchierboom picture ErikSchierboom  Â·  3Comments

FridaTveit picture FridaTveit  Â·  6Comments

FridaTveit picture FridaTveit  Â·  4Comments

FridaTveit picture FridaTveit  Â·  6Comments