java - Promise 返回 play.libs.F$Promise@65722df2 而不是字符串值

标签 java playframework promise future

所以我只是在 Play 中进行实验,我想看看是否可以使用 Promise 函数返回一个字符串。

在此示例中,我尝试获取 UserFirstName 并获取 play.libs.F$Promise@65722df2 的值。

  public static String retrieveUserFirstName(String ch, Service Service,
                                     SessionContext SessionContext, String aN) {

      return Service.getInformation(UteContextArgs.getProcessingContext(),
              SessionContext, aN, ch)
              .filter(info -> info instanceof Information)
              .filter(info -> Constants.ch.equalsIgnoreCase(ch))
              .map(info -> {
                  Information information = (Information) info;
                  return information.getFirstName();
              }).toString();
  }


  public void trySomething (){

      String userFirstName = retrieveUserFirstName(ch, Service,
                                     SessionContext, aN);

      logger.info (context, "here is the userfirstname={}", userFirstName);

  }

  public F.Promise<Information> getInformation(...) {
  ...
  }

在运行时,如果我尝试以字符串形式操作变量,我会得到“空指针异常”。

日志显示:

  here is the userfirstname=play.libs.F$Promise@ca3706e

最佳答案

您当前获取的是 Promise 本身的字符串表示形式,而不是它的 String 结果。

您需要get Promise 的结果。

关于java - Promise 返回 play.libs.F$Promise@65722df2 而不是字符串值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53508745/

相关文章:

java - 自定义 ListCellRenderer 不会改变背景颜色

java - SQLException - 无效的游标状态

javascript - Puppeteer page.content() - 将已解决的 promise 写入列表

javascript - AngularJS 的链式 promise

java - 如何使用SwingWorker?

java - 为什么枚举构造函数不能具有 protected 或公共(public)访问修饰符

playframework - 在 Play 2 SBT 项目中包含 Lucene nightly jar

playframework - Play - HikariCP 连接未释放回池

linux - 使用 Play Framework 在 Linux 上本地进行 HTTPS

javascript - Angular JS $http Promise 的行为是否像真正的 $q Promise 一样?