0

I am building an App using CameraX API. I'm following android codelab example. In Codelab, The project is written on Kotlin, but in my project, I am using Java. I can't understand how do I convert these statements to java? Even I don't know, what is this line does.

// Get a stable reference of the modifiable image capture use case
val imageCapture = imageCapture ?: return
  • @dominicoder No, I just want to know how is it works. I am not familiar with ```?:```. Thank you. – Abu Sufian Shawon Sep 19 '21 at 09:17
  • @AbuSufianShawon - "No, I just want to know how is it works. I am not familiar with ?:. Thank you." - The only question in your post is literally "I can't understand how do I convert these statements to java?", but OK. – dominicoder Sep 20 '21 at 04:26

1 Answers1

1

Koltin's null-safety: https://kotlinlang.org/docs/null-safety.html

The ?: in Kotlin is called elvis-operator and it replaces Java's:

if (imageCapture == null) {
    return
}

The code is checking if imageCapture is null and if so it returns and does not continue to the code below.

gioravered
  • 1,758
  • 3
  • 19
  • 30