1
votes

My App built with Codename One features a Camera preview. I need to resort to the Native Interface implementation (so far Android) to show this preview. On some (older) Android devices I also need to call Camera.autofocus(AutofocusCallback) to make a sharp preview.

Android studio suggests me to use lambda expression to define the callback :

mCamera.autoFocus((b, camera) -> Log.d(TAG, "Camera may have focused"));

When I debug my project it wortks.

However when I copy paste this piece of code in Codename One native interface implementation, and send the Android build, the build process fails with the following error :

error: ')' expected
            mCamera.autoFocus((b, camera) -> Log.d(TAG, "Camera may have focused"));
                                ^
error: illegal start of expression
            mCamera.autoFocus((b, camera) -> Log.d(TAG, "Camera may have focused"));
                                           ^
error: ';' expected
            mCamera.autoFocus((b, camera) -> Log.d(TAG, "Camera may have focused"));

To get the build I have to convert the lambda into the more traditional :

mCamera.autoFocus(new Camera.AutoFocusCallback() {
                @Override
                public void onAutoFocus(boolean b, Camera camera) {
                    Log.d(TAG, "Camera may have focused");
                }
            });

Can't I use lambda in native interface implementation whereas it works flawlessly in Codename One code ?

Any help appreciated,

1

1 Answers

1
votes

Lambdas are are Java 8 feature. Is your codename one project a Java 8 project? The documentation suggests you have to explicitly enable Java 8 by setting "source" and "target" values in your build.xml to 1.8 as well as as set a build hint java.version=8. There are also some other suggestions checking which java version your ide uses: https://www.codenameone.com/blog/java-8-support.html