承诺返回 play.libs.F$Promise@65722df2 而不是字符串值
Promise Returning play.libs.F$Promise@65722df2 instead of String Value
所以我只是在 Play 中进行试验,我想看看是否可以使用 promise 函数 return 字符串。
在这个例子中,我试图获取一个 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(...) {
...
}
在运行时,如果我尝试将变量作为字符串进行操作,我会得到 "null pointer exception".
日志显示:
here is the userfirstname=play.libs.F$Promise@ca3706e
您目前正在获取 Promise
本身的字符串表示形式,而不是其 String
结果。
您需要get
Promise 的结果。
所以我只是在 Play 中进行试验,我想看看是否可以使用 promise 函数 return 字符串。
在这个例子中,我试图获取一个 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(...) {
...
}
在运行时,如果我尝试将变量作为字符串进行操作,我会得到 "null pointer exception".
日志显示:
here is the userfirstname=play.libs.F$Promise@ca3706e
您目前正在获取 Promise
本身的字符串表示形式,而不是其 String
结果。
您需要get
Promise 的结果。