Skip to content

[java] LambdaCanBeMethodReference: False positive on overloaded methods #5043

@Wolf2323

Description

@Wolf2323

Affects PMD Version: 7.1.0

Rule: LambdaCanBeMethodReference

Please provide the rule name and a link to the rule documentation:
https://pmd.github.io/pmd/pmd_rules_java_codestyle.html#lambdacanbemethodreference

Description:
When a method is overloaded like this

    public void closeInventory();
    public void closeInventory(@NotNull InventoryCloseEvent.Reason reason);

it is not possible to use a method reference, but the rule report it

Code Sample demonstrating the issue:

            Bukkit.getScheduler().runTask(BetonQuest.getInstance(), () -> player.closeInventory());

Expected outcome:
no violation

[INFO] PMD Failure: org.betonquest.betonquest.conversation.InventoryConvIO:392 Rule:LambdaCanBeMethodReference Priority:3 Lambda expression could be written as a method reference: player::closeInventory.

Running PMD through: Maven

Metadata

Metadata

Assignees

Labels

a:false-positivePMD flags a piece of code that is not problematic

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions