TimurMahammadov / google-collections

Automatically exported from code.google.com/p/google-collections
Apache License 2.0
0 stars 0 forks source link

Have Predicate<T> extend Function<T,Boolean> #58

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Why does Predicate<T> not simply extend the interface Function<T,Boolean>?
All predicates are technically functions returning boolean, so there is no
conceptual problem there. The inherent relationship between the two
interfaces would obviously be valuable given the existence of:

*Functions.forPredicate(Predicate)
*Predicates.compose(Predicate, Function) 
*http://code.google.com/p/google-collections/issues/detail?id=19

Original issue reported on code.google.com by estebis...@gmail.com on 10 Apr 2008 at 5:03

GoogleCodeExporter commented 9 years ago
The Predicate Javadoc has the answer:

NOTE: This interface could technically extend Function, since a predicate is 
just a
special case of a function (one that returns a boolean). However, since 
implementing
this would entail changing the signature of the apply method to return a Boolean
instead of a boolean, which would in turn allow people to return null from their
predicate, which would in turn enable code that looks like if
(myPredicate.apply(myObject)) ...  to throw a NullPointerException, it was 
decided
not to make this change.

Original comment by cpov...@google.com on 10 Apr 2008 at 5:31

GoogleCodeExporter commented 9 years ago

Original comment by kevin...@gmail.com on 10 Apr 2008 at 5:58