redhat-developer / redhat-developer/vscode-java
The method is ambiguous for the type
未關閉
@snjeza 已經在處理了。
開始於 2025年3月4日。
- 主要語言
- TypeScript
- 星號
- 2.3k
- 分支
- 547
- 平均合併
- 20 小時 1 分鐘
- 30 天內合併 PR
- 11
描述
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:
貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
評估
這個 Issue 還沒有評估資料。