eclipse-jdt / eclipse-jdt/eclipse.jdt.core

ECJ error due to type inference problem with generic method

Open
#224 0 comments 0 reactions 0 assignees View on GitHub
bug compiler
Dominant language
Java
Stars
237
Forks
195
Avg merge
1d 12h
Merged PRs (30d)
47

Description

I have bumped into code that compiles with javac but gives an error when compiling with ECJ (on vscode). Here is an attempt to extract the essential parts of the original code into standalone example:

```java
package example;

import java.util.HashMap;
import java.util.Map;

public class App {

public static void main(String[] args) throws Exception {
// Following fails to compile on ECJ, but it compiles successfully with javac.
// The error I get:
// The method myMethod(Map) in the type App is not applicable for the arguments (Map)
myMethod(App.failingExample(HashMap::new));

// Following compiles with both compilers.
// Giving a "hint" to compiler seems to fix ECJ compilation.
myMethod(App.>failingExample(HashMap::new));

// Following compiles with both compilers.
myMethod(successfulExample(HashMap::new));
}

public static void myMethod(Map arg) throws Exception {
}

@FunctionalInterface
public interface FailingMapBuilder> {
T build();
}

public static > T failingExample(FailingMapBuilder factory) throws Exception {
return factory.build();
}

@FunctionalInterface
public interface SuccesfulMapBuilder {
T build();
}

public static > T successfulExample(SuccesfulMapBuilder factory) throws Exception {
return factory.build();
}
}
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.