java - 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
解决方案
您当前正在获取Promise
自身的字符串表示形式,而不是其String
结果。
你需要get
Promise 的结果。
推荐阅读
- events - Esper 没有保护对象并导致聚合对象 oom
- android - 在android中单击一个按钮而不是它的操作按钮时关闭一个快餐栏
- java - 如何从 Mockito 类中为不返回值的 Save 方法调用/生成异常?
- react-native - React-Native run-android:expo SDK 需要 Expo 才能运行。似乎本机 Expo 模块不可用,并且此代码未在 Expo 上运行
- typescript - TypeScript:销毁参数时如何指定函数参数的类型?
- physics - ARKit 物理对象逐步通过跟踪平面
- jenkins - 如何使用 Jenkins 将归档文件发布到 Confluence
- javascript - 播放幻灯片动画时 Div 的宽度减小
- r - 如何查找年和周格式的两个日期之间的时间间隔,例如。201630 和 201951 在 r
- docker - 如何修复“提供但未定义的标志:-console”