布尔供应商 Java 等待条件为 true

发布于 2025-01-20 12:47:01 字数 341 浏览 0 评论 0原文

我试图等待,直到 areHere 列表中存在条件(我正在等待的那个)。我正在尝试与 BooleanSupplier 合作,但无法让它工作,不确定我的错误在哪里:

String theOne = "pika";

final BooleanSupplier itsHere = () -> {
    List <String> areHere = getSomeList();
    for (String eachOne : areHere) {
        if(eachOne.equals(theOne)) { return TRUE; }
    } return FALSE;
};

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;
};

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

倾城花音 2025-01-27 12:47:01

你需要执行供应商。您刚刚声明了供应商。但没有被执行。

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);
    
  }
}

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);
    
  }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文