Is there a predicate with a null argument?

Is there a default interface used as a null argument Predicate, which essentially is Supplier<Boolean>, which, again, is essentially:

public interface Condition {
  boolean test();
}

If not (I can't find him), then why won't he be absent? Isn't that very helpful?

+4
source share
2 answers

The only scenario I could see for him is a function that uses the global state to determine the return value.

In this case, this is an abuse of this interface. However, instead, you can pass this global variable as a parameter, and everything will work as expected.

+3
source

"", , (true | false). , , 2, ( ) 2 ?

:

if() {
   doFoo();
}

, doFoo()?! true . , .

+1

Source: https://habr.com/ru/post/1540782/


All Articles