Java中的Pusher聊天包连接回调
我正在尝试从SDK站点实现Pusher聊天包:。我更喜欢完全用Java编写代码 在示例中,有以下代码块:Java中的Pusher聊天包连接回调,java,pusher,chatkit,Java,Pusher,Chatkit,我正在尝试从SDK站点实现Pusher聊天包:。我更喜欢完全用Java编写代码 在示例中,有以下代码块: chatManager.connect { result -> when (result) { is Result.Success -> { // We have connected! currentUser = result.value // CurrentUser } is Result.Failure -> {
chatManager.connect { result ->
when (result) {
is Result.Success -> {
// We have connected!
currentUser = result.value // CurrentUser
}
is Result.Failure -> {
// Failure
handleConnectionError(result.error)
}
}
}
但是,上面的代码是用Kotlin编写的。在我自己的代码中,mCurrentUser
即使在chatManager.connect
方法运行之后也是空的
我将Android Studio升级为运行Java 8,并尝试使用以下代码:
chatManager.connect(result -> {
if (result instanceof Result.Success) {
mCurrentUser = ((Result.Success<CurrentUser, Error>) result).getValue();
}
if (result instanceof Result.Failure) {
System.out.print(result);
}
return Unit.INSTANCE;
});
chatManager.connect(结果->{
if(result.Success的结果实例){
mCurrentUser=((Result.Success)Result.getValue();
}
if(result.Failure的结果实例){
系统输出打印(结果);
}
返回Unit.INSTANCE;
});
当我逐步使用调试器时,将跳过整个块。连接方法记录成功的连接,但结果
始终为空
。有人能告诉我如何使用侦听器编写相同的回调吗?或者,向我展示lambda表达式的问题
顺便说一下,chatManager.connect
具有功能1