Skip to content

Incorrect IntelliJ error when using method reference for constructor with optional parameters #704

@EotT123

Description

@EotT123

IntelliJ incorrectly flags a method reference to a constructor that includes optional parameters (without providing all optional parameters) as an error, even though the code compiles fine.

public class Foo {
    public Foo(String test, String bar="bar") { }
}

Function<String, Foo> fooFunction = test -> new Foo(test);
Function<String, Foo> fooFunction2 = Foo::new; // ERROR Bad return type in method reference: cannot convert void to test.Test.Foo
BiFunction<String, String, Foo> fooFunction3 = Foo::new; // OK when all parameters are provided

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