(#) Lambda Parameters Last !!! WARNING: Lambda Parameters Last This is a warning. Id : `LambdaLast` Summary : Lambda Parameters Last Note : **This issue is disabled by default**; use `--enable LambdaLast` Severity : Warning Category : Interoperability: Kotlin Interoperability Platform : Any Vendor : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 Since : 3.2.0 (September 2018) Affects : Kotlin and Java files Editing : This check runs on the fly in the IDE editor See : https://android.github.io/kotlin-guides/interop.html#lambda-parameters-last Implementation : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/InteroperabilityDetector.kt) Tests : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/InteroperabilityDetectorTest.kt) To improve calling this code from Kotlin, parameter types eligible for SAM conversion should be last. (##) Example Here is an example of lint warnings produced by this check: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text src/test/pkg/Test.java:11:Warning: Functional interface parameters (such as parameter 1, "run", in test.pkg.Test.error1) should be last to improve Kotlin interoperability; see https://kotlinlang.org/docs/reference/java-interop.html#sam-conversions [LambdaLast] public void error1(Runnable run, int x) { } ----- src/test/pkg/Test.java:12:Warning: Functional interface parameters (such as parameter 1, "sam", in test.pkg.Test.error2) should be last to improve Kotlin interoperability; see https://kotlinlang.org/docs/reference/java-interop.html#sam-conversions [LambdaLast] public void error2(SamInterface sam, int x) { } ----- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Here are the relevant source files: `src/test/pkg/Test.java`: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~java linenumbers package test.pkg; @SuppressWarnings("ClassNameDiffersFromFileName") public class Test { public void ok1() { } public void ok1(int x) { } public void ok2(int x, int y) { } public void ok3(Runnable run) { } public void ok4(int x, Runnable run) { } public void ok5(Runnable run1, Runnable run2) { } public void ok6(java.util.List list, boolean b) { } public void error1(Runnable run, int x) { } public void error2(SamInterface sam, int x) { } public interface SamInterface { void samMethod(); @Override String toString(); default void other() { } } } ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ `src/test/pkg/test.kt`: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin linenumbers package test.pkg fun ok1(bar: (Int) -> Int) { } fun ok2(foo: Int) { } fun ok3(foo: Int, bar: (Int) -> Int) { } fun ok4(foo: Int, bar: (Int) -> Int, baz: (Int) -> Int) { } // Lamda not last, but we're not flagging issues in Kotlin files for the // interoperability issue fun error(bar: (Int) -> Int, foo: Int) { } ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ You can also visit the [source code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/InteroperabilityDetectorTest.kt) for the unit tests for this check to see additional scenarios. The above example was automatically extracted from the first unit test found for this lint check, `InteroperabilityDetector.testLambdaLast`. To report a problem with this extracted sample, visit https://issuetracker.google.com/issues/new?component=192708. (##) Suppressing You can suppress false positives using one of the following mechanisms: * Using a suppression annotation like this on the enclosing element: ```kt // Kotlin @Suppress("LambdaLast") fun method() { problematicStatement() } ``` or ```java // Java @SuppressWarnings("LambdaLast") void method() { problematicStatement(); } ``` * Using a suppression comment like this on the line above: ```kt //noinspection LambdaLast problematicStatement() ``` * Using a special `lint.xml` file in the source tree which turns off the check in that folder and any sub folder. A simple file might look like this: ```xml <?xml version="1.0" encoding="UTF-8"?> <lint> <issue id="LambdaLast" severity="ignore" /> </lint> ``` Instead of `ignore` you can also change the severity here, for example from `error` to `warning`. You can find additional documentation on how to filter issues by path, regular expression and so on [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html). * In Gradle projects, using the DSL syntax to configure lint. For example, you can use something like ```gradle lintOptions { disable 'LambdaLast' } ``` In Android projects this should be nested inside an `android { }` block. * For manual invocations of `lint`, using the `--ignore` flag: ``` $ lint --ignore LambdaLast ...` ``` * Last, but not least, using baselines, as discussed [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html).