Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The method is ambiguous for the type #3955

Open
quangkevin opened this issue Feb 18, 2025 · 1 comment
Open

The method is ambiguous for the type #3955

quangkevin opened this issue Feb 18, 2025 · 1 comment
Assignees

Comments

@quangkevin
Copy link

quangkevin commented Feb 18, 2025

Type: Bug

VS Code is showing error for this code snippet that standard javac has no problem with. It's a combination of having overload methods accepting two different interfaces and a lambda expression that's using while loop.

public class Test {
  public static void main(String[] args) throws Exception {
    System.out.println("Hello, World!");

    test(x -> {
        while (x.length() > 0) {
            System.out.println(x);
            x = x.substring(1);
        }
    });
  }

  public static void test(Consumer<String> consumer) {
      consumer.accept("Hello, World!");
  }

  public static void test(Function<String, Integer> function) {
      System.out.println(function.apply("Hello, World!"));
  }

  public interface Consumer<T> {
      void accept(T t);
  }

  public interface Function<T, R> {
      R apply(T t);
  }
}

Error: The method test(Test.Consumer) is ambiguous for the type Test

Extension version: 1.39.0
VS Code version: Code 1.96.4 (cd4ee3b1c348a13bafd8f9ad8060705f6d4b9cba, 2025-01-16T00:16:19.038Z)
OS version: Linux x64 5.4.0-205-generic
Modes:

@snjeza snjeza self-assigned this Mar 4, 2025
@snjeza
Copy link
Contributor

snjeza commented Mar 4, 2025

This is an upstream eclipse.jdt.core issue. I can reproduce it using the jdt.core master branch.
@quangkevin Could you create a new issue at https://github.com/eclipse-jdt/eclipse.jdt.core/issues/new ?
You can also try to set "java.jdt.ls.javac.enabled": "on",.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants