You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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 strain, we "wish" that List had keep(), discard(), and filter() methods on it. It doesn't, so we're including them here.
Please include a HINT.md file in strain 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.
The text was updated successfully, but these errors were encountered:
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
andCollections
.In the case of the exercise
strain
, we "wish" thatList
hadkeep()
,discard()
, andfilter()
methods on it. It doesn't, so we're including them here.Please include a
HINT.md
file instrain
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.The text was updated successfully, but these errors were encountered: