Kotlin – 不变的参考

我正在尝试使用新的相机硬件API(android.hardware.camera2)为我的android应用程序的示例代码。 首先,我通过Android Studio的Kotlin插件的自动转换function将Java代码转换为Kotlin代码。 下面是一段转换后的代码:

private val mCaptureCallback = object : CameraCaptureSession.CaptureCallback() { private fun process(result: CaptureResult) { when (mState) { STATE_PREVIEW -> { }// We have nothing to do when the camera preview is working normally. STATE_WAITING_LOCK -> { val afState = result.get(CaptureResult.CONTROL_AF_STATE) if (CaptureResult.CONTROL_AF_STATE_FOCUSED_LOCKED == afState || CaptureResult.CONTROL_AF_STATE_NOT_FOCUSED_LOCKED == afState) { // CONTROL_AE_STATE can be null on some devices val aeState = result.get(CaptureResult.CONTROL_AE_STATE) if (aeState == null || aeState == CaptureResult.CONTROL_AE_STATE_CONVERGED) { mState = STATE_WAITING_NON_PRECAPTURE captureStillPicture() } else { runPrecaptureSequence() } } } STATE_WAITING_PRECAPTURE -> { // CONTROL_AE_STATE can be null on some devices val aeState = result.get(CaptureResult.CONTROL_AE_STATE) if (aeState == null || aeState == CaptureResult.CONTROL_AE_STATE_PRECAPTURE || aeState == CaptureRequest.CONTROL_AE_STATE_FLASH_REQUIRED) { mState = STATE_WAITING_NON_PRECAPTURE } } STATE_WAITING_NON_PRECAPTURE -> { // CONTROL_AE_STATE can be null on some devices val aeState = result.get(CaptureResult.CONTROL_AE_STATE) if (aeState == null || aeState != CaptureResult.CONTROL_AE_STATE_PRECAPTURE) { mState = STATE_PICTURE_TAKEN captureStillPicture() } } } } 

我得到了未解决的参考错误:

 CaptureResult.CONTROL_AF_STATE_FOCUSED_LOCKED CaptureResult.CONTROL_AF_STATE_NOT_FOCUSED_LOCKED CaptureResult.CONTROL_AE_STATE_CONVERGED CaptureResult.CONTROL_AE_STATE_PRECAPTURE CaptureRequest.CONTROL_AE_STATE_FLASH_REQUIRED 

但是这些常量在原始的Java代码中被识别。 有任何解决这些错误?

Kotlin language will be the best programming language for Android.