所以我只是在 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/