redhat-developer / redhat-developer/vscode-java
Build/compilation issue with wildcard types
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 2.3k
- Forks
- 546
- Avg merge
- 20h 1m
- Merged PRs (30d)
- 11
Description
Following is some sample code to replicate the issue:
import java.util.List;
public class Tester {
<T extends List<? extends Entry<?, ?>>> Entry<?, ?> test(T input) {
return ConcreteEntry.from(input.get(0)); // Error here
}
public static void main(String[] args) {
Tester tester = new Tester();
System.out.println(tester.test(List.of(new ConcreteEntry<>("a", 1))));
}
}
interface Entry<K, V> {
K getKey();
V getValue();
}
class ConcreteEntry<K, V> implements Entry<K, V> {
private final K key;
private final V value;
public ConcreteEntry(K key, V value) {
this.key = key;
this.value = value;
}
public static <K, V> ConcreteEntry<K, V> from(Entry<K, V> entry) {
return new ConcreteEntry<>(entry.getKey(), entry.getValue());
}
@Override
public K getKey() {
return key;
}
@Override
public V getValue() {
return value;
}
@Override
public String toString() {
return this.key + "=" + this.value;
}
}
The test method throws the error The method from(Entry<K,V>) in the type ConcreteEntry is not applicable for the arguments (capture#1-of ? extends Entry<?,?>) Java(67108979). The expected behaviour is correct compilation. However, enabling the "java.jdt.ls.javac.enabled" works, but is not an ideal solution.
This occurs with the latest Language Support for Java(TM) by Red Hat - v1.42.0.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the reported diagnostic with the Java sample in the issue using Language Support for Java v1.42.0, first with the normal compiler path and then with java.jdt.ls.javac.enabled enabled. Compare both results and confirm that the wildcard-type example compiles without an error on the corrected path.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 38/100