I am trying to get to wait until there exists the condition (theOne, that I am waiting for) in the list of areHere. I am trying to work with BooleanSupplier but can't get it to work, not sure where is my mistake:
String theOne = "pika";
final BooleanSupplier itsHere = () -> {
List <String> areHere = getSomeList();
for (String eachOne : areHere) {
if(eachOne.equals(theOne)) { return TRUE; }
} return FALSE;
};
you need to execute supplier. You just declared supplier. But not executed.
import java.util.function.BooleanSupplier;
import java.util.*;
public class Main{
public static void main(String[] args) {
String theOne = "pika";
final BooleanSupplier itsHere = () -> {
List <String> areHere = Arrays.asList("1","2","pika");
for (String eachOne : areHere) {
if(eachOne.equals(theOne)) { return Boolean.TRUE; }
} return Boolean.FALSE;
};
Boolean result = itsHere.getAsBoolean(); //this code execute supplier and get result.
System.out.println(result);
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.