Skip to content

Improved suggestions when unnamed variables are used #5553

@ben-manes

Description

@ben-manes

In Java, the _ is not an implicit variable, unlike it in groovy/kotlin, so the substitution does not work. The recommendation is otherwise excellent.

warning: [UnnecessaryOptionalGet] This code can be simplified by directly using the lambda parameters instead of calling get..() on optional.
    return firmId.map(_ -> ShareIdentity.builder()
                     ^
    (see https://errorprone.info/bugpattern/UnnecessaryOptionalGet)
  Did you mean '.sharedToFirmId(_)'?
     return firmId.map(_ -> ShareIdentity.builder()
         .sharedToUserId(edgeId(sharedTo.getUser()))
-        .sharedToFirmId(firmId.get())
+        .sharedToFirmId(_)
         .identityType(PHONE_NUMBER)
         .identity(phoneNumber)
         .build());

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions