首页 > 解决方案 > Promise Returning play.libs.F$Promise@65722df2 instead of String Value

问题描述

So I'm just experimenting in Play and I wanted to see if I could use a promise function to return a String.

In this example I am trying to grab a UserFirstName and instead get the value of 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(...) {
  ...
  }

Upon runtime if I try to manipulate the variable as a string in anyway I get "null pointer exception".

logs show:

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

标签: javaplayframeworkpromisefuture

解决方案


您当前正在获取Promise自身的字符串表示形式,而不是其String结果。

你需要getPromise 的结果。


推荐阅读