Android Kotlin 语句到 Java 转换

Android Kotlin Statement to Java Convert

我正在使用 CameraX API 构建应用程序。我正在关注 android codelab 示例。在 Codelab 中,该项目是用 Kotlin 编写的,但在我的项目中,我使用的是 Java。我不明白如何将这些语句转换为 java?连我都不知道,这行是干什么的。

// Get a stable reference of the modifiable image capture use case
val imageCapture = imageCapture ?: return

Koltin 的空安全性:https://kotlinlang.org/docs/null-safety.html

Kotlin 中的 ?: 称为 elvis-operator,它取代了 Java 的:

if (imageCapture == null) {
    return
}

代码正在检查 imageCapture 是否为 null,如果是,则 returns 并且不会继续下面的代码。